print - for printing whole line, but delimeters are changed to spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print - for printing whole line, but delimeters are changed to spaces
# 1  
Old 05-25-2012
print - for printing whole line, but delimeters are changed to spaces

Hi consider the source file

Code:
R|field1|field2

using the print statement in awk prints it as
Code:
R field1 field2

Is there an easier way to print the whole line in its original format (i.e. with | delimiters) than doing print $1"|"$2"|"$3 ??

Thanks

Storms
# 2  
Old 05-25-2012
The special OFS variable controls what awk's output separator is.
Code:
awk -F'|' '{ ... }' OFS='|' filename

You can even use this to transform lines with one separator into a different separator, but beware that awk won't actually alter the line until you write to the line or tokens in some way. A no-op like $1=$1 would do.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing a specific number of spaces

when given a file name, im looking for the most efficient way to turn each letter of the file name into spaces. for instance, the way im thinking of going about this is this: MYFILE=check_disks.sh CHANUM=$(echo ${MYFILE} | awk '{ print length }') printf '%s\n' $CHANUM as you can see... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

Sort file based on number of delimeters in line

Hi, Need to sort file based on the number of delimeters in the lines. cat testfile /home/oracle/testdb /home /home/oracle/testdb/newdb /home/oracle Here delimeter is "/" expected Output: /home/oracle/testdb/newdb /home/oracle/testdb /home/oracle /home (3 Replies)
Discussion started by: Sumanthsv
3 Replies

3. Shell Programming and Scripting

Print between pattern without spaces

I seem to have hit a curious problem where sed and awk based regex do not seem to work. Perhaps I am missing a switch to look within the same line and not across lines. I have input as follows: ... (4 Replies)
Discussion started by: jamie_123
4 Replies

4. Shell Programming and Scripting

Echo printing a line in 2 lines; expected to print in one line

Dear All, fileName: therm.txt nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41 1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2 -2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3 ... (7 Replies)
Discussion started by: linuxUser_
7 Replies

5. Shell Programming and Scripting

Split a line into multiple lines based on delimeters

Hi, I need help to split any lines that contain ; or , input.txtAc020 Not a good chemical process AC030 many has failed, 3 still maintained AC040 Putative; epithelial cells AC050 Predicted binding activity AC060 rodC Putative; upregulated in 48;h biofilm vs planktonic The output... (8 Replies)
Discussion started by: redse171
8 Replies

6. Shell Programming and Scripting

awk help about show all the line beside the changed line

awk '/abc/{print $2}' This will show the line contains abc and only show the "two filed" But I want to the line contains "abc" will only show $2, other line still show. and I want to know awk's way about not only show the line besides changed line Thanks (2 Replies)
Discussion started by: yanglei_fage
2 Replies

7. Shell Programming and Scripting

print columns with spaces

Hi All I've a file which is similar to the one given below column1 coulmn2 column3 column4 A B C D X Y F G H I would like to get it in this format A|B|C|D ||X|Y F||G|H Is... (4 Replies)
Discussion started by: Celvin VK
4 Replies

8. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

9. Shell Programming and Scripting

sed - print old line and new changed line

hello, i have a file "TEST" and want to change the digit(s) after "=" . but i also want to print the old entry with a comment (for information). i want to use "sed", is it possible ? file: TEST = 10 # comment default value: 0 sed , with "p" , i can print the old entry, but i want to... (2 Replies)
Discussion started by: bora99
2 Replies

10. Shell Programming and Scripting

How to print empty line when the a field is changed

Hi all, I have this input file .. BSS01 107 Swafieh 11/06/2008 12:06:57 BSS01 111 Ramada_Hotel 12/06/2008 11:37:20 BSS01 147 Kalha_Rep 11/06/2008 19:13:39 BSS01 147 Kalha_Rep ... (9 Replies)
Discussion started by: yahyaaa
9 Replies
Login or Register to Ask a Question