473,890 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems while reading each lines and performing operations in each line

14 New Member
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|+97798 04808287|spice-6464|16|
2008-04-18 11:11:52|spice-7676|+977980480 8287|16|
2008-04-18 11:12:43|+97798 04808287|spice-6464|16|
2008-04-18 11:12:43|spice-7676|+977980480 8287|16|
2008-04-18 11:14:04|+97798 04808287|spice-6464|16|

so how can i perform this task

thanks for any suggestion
with regards,
Creeds
Apr 29 '08 #1
4 2230
ashitpro
542 Recognized Expert Contributor
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 New Member
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 Recognized Expert Contributor
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 New Member
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"|"subst r($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
3146
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 started, opens a FIFO and opens it with open(infifo, 'r'). Then I check the content of the file with while 1: line = serverIn.readline()
7
2822
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 Col3 Col4 A0012430 REKAL TVÄTTMEDEL EKOMAX 0,5L ST 75.9000
6
3805
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 trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple coding convention for reading in a flatfile - one record at a time?? SCANF does not work because of...
13
6126
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 "columns", and several "cells" represent an objects in my application. What I need to do is, read the text file line by line, parse the
11
6102
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 dicts with larger no. of features. Now i want to check each pair to see if they are connected...element of this pair will be one from the first list and one from the second....e.g for 'ab' i want to check if 1 and 3 are connected,then 1 and...
12
3059
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
1808
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 read a lilne then put into the corresponding box...it just seems like a task i should be able to complete in a few lines...rather than quite a few commands. for example what i do at the moment is: read a line place into first text box
2
1365
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 appears in the toolbar saying that "Visual Studio is busy waiting for an operation to complete" and the IDE is completely frozen. The hang occurs when one or more background threads are: 1) performing file-read operations via StreamReader, AND......
1
2405
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++) running and this is what it does: 1) creates the number of children the user indicates 2) can read the number lines in the TXT file 3) tells how many lines each child will read This is how I understand what the program will do and I want to make...
0
9977
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9816
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9618
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6036
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4667
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4260
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3268
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.