473,378 Members | 1,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Problems while reading each lines and performing operations in each line

14
Hello !!
i have a text file, from where i have to perform an operation such as awk for every lines.
i can count the number of lines with cat filename | wc -l , no problem with that.

my scenario:
i take a input from a file, i count the length ofcertian paramater with substring and do the if else condition.
but i have to perform this action in every line....

a code snippet...

echo $File
#count =$( cat /home/postgres/edt1/$File-spice-7676.txt.edt1 |wc -l)
#echo $count
#while [ "$count" != $check ]
#do
#count=$count-1

for LINE in $( cat /home/postgres/edt1/$File-spice-7676.txt.edt1 )
do
v=$(awk -F "|" '{ print length($2)}' /home/postgres/edt1/$File-spice-7676.txt.edt1)

echo $v

if [ $v -lt $X ]

then

awk -F"|" '{print $1"|"substr($2,length($2)-6,length($2))"|"$3"|"$4}' /home/postgres/edt1/$File-spice-7676.txt.edt1 >> /home/postgres/edt1/test.txt
echo " inside less"
else
echo " no"
awk -F"|" '{print $1"|"$2"|"$3"|1|"$4}' /home/postgres/$File-spice-7676.txt.edt > /home/postgres/edt1/test.txt

fi
done

..........
i am not able to proceed with LINE as it thinks as a new line when it finds spaces within a line,
i tried to count the number of lines in the file and think of decresing its value evey time, but also i didnt get the result

my file /home/postgres/edt1/$File-spice-7676.txt.edt1 )
is sum wot like that...

2008-04-18 11:11:52|+9779804808287|spice-6464|16|
2008-04-18 11:11:52|spice-7676|+9779804808287|16|
2008-04-18 11:12:43|+9779804808287|spice-6464|16|
2008-04-18 11:12:43|spice-7676|+9779804808287|16|
2008-04-18 11:14:04|+9779804808287|spice-6464|16|

so how can i perform this task

thanks for any suggestion
with regards,
Creeds
Apr 29 '08 #1
4 2199
ashitpro
542 Expert 512MB
change this line:
for LINE in $( cat /home/postgres/edt1/$File-spice-7676.txt.edt1 )

to:

cat /home/postgres/edt1/$File-spice-7676.txt.edt1 | while read LINE
Apr 29 '08 #2
creeds
14
hello
yeah i already did that, but i again got strucked with

if [ "$V" -gt "$X" ]
the error shows unary operator expected,
i tried with all combination like "" or "$x" or "10" etc etc,
but shows error like interger expected or unary operator error...
so hw to solve this basic problem???
with regards,
suman
Apr 30 '08 #3
ashitpro
542 Expert 512MB
hello
yeah i already did that, but i again got strucked with

if [ "$V" -gt "$X" ]
the error shows unary operator expected,
i tried with all combination like "" or "$x" or "10" etc etc,
but shows error like interger expected or unary operator error...
so hw to solve this basic problem???
with regards,
suman

just print values of $V and $X
to use -gt/-lt/-eq in comparison input must be integers...
Apr 30 '08 #4
creeds
14
Hello
Thanks for suggestion ,
now i cud solve my problem but with a lengthy process by sendign value to a file and getting its value from there..it was lengthy but i cud do my work now still it gave me sum headache
--------------------------------
do
echo $line
V= echo $line |awk 'BEGIN{FS="|"} {print length($3)}' > /home/postgres/v.txt
#echo "THE V IS:"$V
#echo "THE V IS:"$V
Y=$(awk '{print $0}' /home/postgres/v.txt)
echo "THE Y IS:"$Y
if [ "$Y" -gt "14" ]; then
echo "greater"
echo $line |awk 'BEGIN{FS="|"} {print $1"|"$2"|"substr($3,length($3)-13,length($3))"|1|"$4}' >> /home/postgres/edt1/final.txt
else
echo "lesser"

echo $line |awk 'BEGIN{FS="|"} {print $1"|"$2"|"$3"|1|"$4}' >> /home/postgres/edt1/final1.txt
fi
done

thanks
Suman
Apr 30 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Tobias Pfeiffer | last post by:
Hi! I want to write a "client-server-application" (only running on the same machine) or actually I've already begun with and have problems with the interprocess communication. The server, when...
7
by: jamait | last post by:
Hi all, I m trying to read in a text file into a datatable... Not sure on how to split up the information though, regex or substrings...? sample: Col1 Col2 ...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
13
by: ACC | last post by:
Hi! I'm developing an application to analyze some information that is inside a text file. The size of the text file goes from 50Mb to 220Mb... The text file is like a table, with "rows" and...
11
by: Girish Sahani | last post by:
I wrote the following code to concatenate every 2 keys of a dictionary and their corresponding values. e.g if i have tiDict1 = tiDict1 = {'a':,'b':} i should get tiDict2={'ab':} and similarly for...
12
by: Yi Xing | last post by:
Hi All, I want to read specific lines of a huge txt file (I know the line #). Each line might have different sizes. Is there a convenient and fast way of doing this in Python? Thanks. Yi Xing
3
by: lizii | last post by:
i have a file - which on each line has some data i need to fill into a box - now although reading in the data is simple enough and putting it in the correct box will be no problem, as i can just...
2
by: Jules Winfield | last post by:
I've been experiencing a problem recently where the debugger hangs for up to ten seconds, even when executing very simple operations (i.e. adding two numbers). During the hang, a little popup...
1
by: Rubenintx | last post by:
Need some help with this code / Using UNIX. The goals is to read a big file (2,000,000) lines, using fork() to create children to help in the process. I am able to get the program (C++)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.