How to print the output in single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print the output in single line
# 1  
Old 08-03-2008
How to print the output in single line

Hi,

Please suggest, how to get the output of below script in single line, its giving me in different lines

______________________
#!/bin/ksh
export Path="/abc/def/ghi";
Home="/home/psingh/prat";
cd $Path;
find $Path -name "*.C#*" -newer "abc.C#1234" -print > $Home
cat $Home | while read line
do
cat $line | awk '/Subject/ {print}' | cut -c 1-35
cat $line | awk '/Date/ {print}' | cut -c 68-120
done
_----------------------

Thank you
# 2  
Old 08-03-2008
The following also avoids the temporary file, and the use of cat. Oh, and the use of cut.

Code:
find $PATH -name "*.C#" -newer "abc.C#1234" -print |
while read file; do
    awk '/Subject/ { s=substr($0,1,35) } /Date/ { d=substr($0,68,53) }  END { print s, d }' "$file"
done

The main thing here really is (1) use an output format which does not include a newline between the items you want to print (I used a space instead); and (2) for efficiency and elegance, combine all the processing into a single awk script.

If Subject always comes before Date, you could do away with the while loop, too.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

2. Shell Programming and Scripting

Multiple pattern match and print the output in a single line

I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line. Sample Log: 2013/06/11 14:29:04 <0999> (725102) Processing batch 02_1231324 2013/06/11... (4 Replies)
Discussion started by: rpm120
4 Replies

3. Shell Programming and Scripting

Print in single line

HI I am having a flle like below . test.txt ssh aaaaaaa@bbbbbbbbb "head -1 /xxxxxx/yyyyyyy/yyyyyyy.sp.issuer_upd_fd" echo /xxxxxx/yyyyyyy/yyyyyyy.sp.issuer_upd_fd ssh aaaaaaa@bbbbbbbbb "head -1 /xxxxxx/yyyyyyy/yyyyyyy.sp.xreff_upd_gm" echo /xxxxxx/yyyyyyy/yyyyyyy.sp.xreff_upd_gm ... (3 Replies)
Discussion started by: ptappeta
3 Replies

4. Shell Programming and Scripting

Find 2 expressions then print in a single line

Guys, need help. I have a file that contains something like this: abc def ghi jkl I want to print the first and last line of the file and the output should be in a single line. so, output should be like this: abc jkl (3 Replies)
Discussion started by: solidhelix08
3 Replies

5. Shell Programming and Scripting

convert single line output to multiple line

Hi all, I have a single line output like below echo $ips 10.26.208.28 10.26.208.26 10.26.208.27 want to convert above single line output as below format. Pls advice how to do ? 10.26.208.28 10.26.208.26 10.26.208.27 Regards Kannan (6 Replies)
Discussion started by: kamauv234
6 Replies

6. Shell Programming and Scripting

Print (echo) variable in a single line

Hi, I have written this code ------------------------------------------------ # !/bin/ksh i=0 while do j=$i while do echo -e $j #printf "%d",$j j=`expr $j - 1` done echo i=`expr $i + 1` done ---------------------------------------------------- The ouput which... (2 Replies)
Discussion started by: rac
2 Replies

7. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

8. Shell Programming and Scripting

Merge multi-line output into a single line

Hello I did do a search and the past threads doesn't really solve my issue. (using various awk commands) I need to combine the output from java -version into 1 line, but I am having difficulties. When you exec java -version, you get: java version "1.5.0_06" Java(TM) 2 Runtime... (5 Replies)
Discussion started by: flagman5
5 Replies

9. Shell Programming and Scripting

Output coming in different line instead of single line

Hi Guys, I have an oracle database, I am trying to query the database and route it to file. But the records instead of coming in a single line, are coming in three lines. Can you please help me.. in this.. sqlplus -s $SRMUserid/$SRMPassword@$SRMServer<< EOF >log.out; select * from... (5 Replies)
Discussion started by: mac4rfree
5 Replies

10. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies
Login or Register to Ask a Question