read a file in shell and put result in a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read a file in shell and put result in a line
# 1  
Old 07-06-2009
read a file in shell and put result in a line

Hi All,

I have a to read a file and put the result in one line. The i am reading from contain the data like below.
1 signifies the beging of the new line.

Quote:
1,109109206398,20090213_00311,10000,ZMK,12,20090630,vsd
2,Available,20090215T21:30:12,munyumbwet,,
1,109109207836,20090213_00311,10000,ZMK,12,20090630,vsd
2,Available,20090215T21:30:12,munyumbwet,,
2,Used,20090618T07:04:31,,979499299,5983307235041
1,109109208607,20090213_00311,10000,ZMK,12,20090630,vsd
2,Available,20090215T21:30:12,munyumbwet,,
1,109109208633,20090213_00311,10000,ZMK,12,20090630,vsd
2,Available,20090215T21:30:12,munyumbwet,,
1,109109208662,20090213_00311,10000,ZMK,12,20090630,vsd
2,Available,20090215T21:30:12,munyumbwet,,

Last edited by vgersh99; 07-06-2009 at 05:03 PM.. Reason: fixed code tag
# 2  
Old 07-06-2009
You mean you have to put all the lines in a file to a single line?

Code:
echo $(cat file)

# 3  
Old 07-06-2009
Quote:
Originally Posted by scottn
You mean you have to put all the lines in a file to a single line?

Code:
echo $(cat file)

Yes, if i can have them in a variable then i be done.
# 4  
Old 07-06-2009
Code:
RESULT=$(echo $(cat file))

# 5  
Old 07-06-2009
Thanks, but how can I ve the result in one line. in the sample data supplied. i would want to have 1 to signifie the beginging the a new line(\n)

---------- Post updated at 03:09 PM ---------- Previous update was at 02:54 PM ----------

Quote:
for i in `cat purged.txt `
do
data=`echo $i`
m=`echo $i |awk -F',' '{print $1}'`
if [$m eq 2]
then
cat $data | tr "\n" "|"
fi
echo $data
done
i have sumthing like ths bt cant work
# 6  
Old 07-06-2009
Code:
nawk -F, '$1==1 {printf (FNR==1)?"":ORS} {printf $0}' myFile

# 7  
Old 07-06-2009
Quote:
Originally Posted by vgersh99
Code:
nawk -F, '$1==1 {printf (FNR==1)?"":ORS} {printf $0}' myFile

Thanks, this worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies

2. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

3. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

4. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

5. Shell Programming and Scripting

how can u read a file line by line in shell script ?

hello , plz help for below script req:- how can we read a file line by line in shell script ? (4 Replies)
Discussion started by: abhigrkist
4 Replies

6. Shell Programming and Scripting

How to put db2 query result into an array in shell script?

Hello, Can someone please advise me how to put the db2 query reult into an array? For example, the query reults are: string A string B string C Then how do I put them into array=string A array=string B ... (2 Replies)
Discussion started by: hanul
2 Replies

7. Shell Programming and Scripting

Read multiple log files and create output file and put the result

OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4 Looking for a script that reads the following log files that gets generated everynight between 2 - 5am Master_App_20090717.log Master_App1_20090717.log Master_App2_20090717.log Master_App3_20090717.log... (2 Replies)
Discussion started by: aavam
2 Replies

8. UNIX for Dummies Questions & Answers

shell script to read file line by line

Hi, I need to read a text file from shell script line by line and copy the feilds of each line. Below is the complete requirement. I've text file which contains ... pgm1 file11 file12 file13 pgm2 file21 file22 pgm3 file31 file32 file33 I'll give input as... (4 Replies)
Discussion started by: ani12345
4 Replies

9. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

10. Shell Programming and Scripting

How to read a line and put it into 3 variables

Hi All, I'll get a file whose 2nd line contains 3 fields: filename(variable length), file size char(10), and record count int(10). How do I cut it and put it into 3 variables? eg: abcd.csv01234567891111111111 now I want: $one = abcd.csv, $two = 0123456789, $three = 1111111111. I also... (8 Replies)
Discussion started by: Mandab
8 Replies
Login or Register to Ask a Question