including spaces in awk output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting including spaces in awk output
# 1  
Old 03-09-2007
including spaces in awk output

I need to tweek my awk output:

Code:
#cat filename
ab   cd   ef:ghi:jk  lm:nop  qrs

#cat filename | awk '{ for(i=3;i<NF+1;i++) printf $i}'
ef:ghi:jklm:nopqrs

I would like the ouput to include the original spaces from columns 3 on:

Code:
ef:ghi:jk  lm:nop  qrs

any suggestions?
# 2  
Old 03-09-2007
Code:
$ echo "ab   cd   ef:ghi:jk  lm:nop  qrs" | awk 'sub($1" +"$2" +","",$0) '
ef:ghi:jk  lm:nop  qrs

or
Code:
$ echo "ab   cd   ef:ghi:jk  lm:nop  qrs" | sed "s/\([^ ]* *\)\{2\}//"
ef:ghi:jk  lm:nop  qrs


Last edited by anbu23; 03-09-2007 at 04:44 PM.. Reason: Added sed solution
# 3  
Old 03-09-2007
using an older version of awk on Solaris 9... the above suggestions do not work. Smilie
# 4  
Old 03-09-2007
then use nawk.
# 5  
Old 03-12-2007
Quote:
Originally Posted by reborg
then use nawk.
thanks bro, works well! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Populating a BASH array with a list of files including spaces-in-the-name

For the record, I already tried telling mgmt and the users to disallow spaces in filenames for this script, but it isn't happening for a number of ID10T-error-based reasons. I have simple list of 3 files in a directory that are named like this: bash-3.2$ ls -1 file* file1 file1 part2... (2 Replies)
Discussion started by: ckmehta
2 Replies

2. Shell Programming and Scripting

Pick the column value including comma from csv file using awk

Source 1 column1 column2 column 3 column4 1,ganesh,1,000,1 222,ram,2,000,5 222,ram,50,000,5 33,raju,5,000,7 33,raju,5,000,7 33,raju,5,000,8 33,raju,5,000,4 33,raju,5,000,1 In my .csv file, third column is having price value with comma (20,300), it has to be considered 1,000 as... (1 Reply)
Discussion started by: Ganesh L
1 Replies

3. UNIX for Dummies Questions & Answers

AWK print last field including SPACES

I have simple test.sh script, see below: bill_code=`echo $record | awk -F"|" '{print $1}'` Fullname=`echo $record | awk -F"|" '{print $3}'` email=`echo $record | awk -F\ '{print $4}'` The last field contains spaces: see csv below: A0222|Y|DELACRUZ|-cc dell@yahoo.com-cc support@yahoo.com ... (9 Replies)
Discussion started by: quay
9 Replies

4. Shell Programming and Scripting

Need help redirecting output to a file including errors

Need help redirecting output to a file including errors if any,I have 2 script namely push.ksh and run.ksh, I'm scp'ing push.ksh to another server and executing remotely via run.ksh, the script run.ksh runs locally but does not capture any errors in "servername.out" file (I tried testing various... (10 Replies)
Discussion started by: mbak
10 Replies

5. Shell Programming and Scripting

Removing spaces from the output of a head command

Im running the below commands in a script. Total_confirms=`cat $OUTPATH/count_po* | head -4 | tail -1` # echo "Total Confirms records we need: $Total_confirms" >> $LOG2 The problem is its always returning 4 spaces before the result.. Can I pipe the result into something else to remove the... (5 Replies)
Discussion started by: Jazmania
5 Replies

6. UNIX for Dummies Questions & Answers

awk printing all columns after (but including) $n

I am piping an "ls -l" to awk so that all it returns is the file size, date, and file name. The problem is that some files may have spaces in the name so awk is only printing the first word in the file name. I won't know how many space-delimited words are in the filename, so what I want to do is... (2 Replies)
Discussion started by: cassj
2 Replies

7. UNIX for Dummies Questions & Answers

Reading a line including spaces

Hi All, I have a script that reads a file and echo it back to std out. Test.txt 1aaaaaaaaaaa . The script is ReadLine.sh #!/bin/ksh cat $1 | while read file do echo $file done I invoke the script as ReadLine.sh Test.txt The output that I get is (1 Reply)
Discussion started by: aksarben
1 Replies

8. Shell Programming and Scripting

Retaining Spaces while redirecting output

I need to merge data from more than one file and I am using while read line_record do field1=`echo $line_record | awk -F "," '{ print $1 }'` echo $line_record >> $outFile if then while read new_linerec do echo $new_linerec... (3 Replies)
Discussion started by: skrakesh
3 Replies

9. Shell Programming and Scripting

Read files including spaces

I am accessing two files. I am using read command to read from the files. For the first file, I need read the fields delimited by spaces, and for the other file, I need to read the whole line as a single field including the spaces. When I used read command for the second file, the spaces... (4 Replies)
Discussion started by: kumariak
4 Replies

10. UNIX for Dummies Questions & Answers

redirecting output, including errors

what's the proper syntax to redirect output, including all errors? ls -la > direct.list makes out put file direct.list but if i'm running a script and i want to include the errors, would i type something like: myscript.scr 2> out_list.txt or will that get the errors only? (1 Reply)
Discussion started by: kymberm
1 Replies
Login or Register to Ask a Question