awk puts newline between fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk puts newline between fields
# 1  
Old 10-12-2010
awk puts newline between fields

I have

Code:
a='123, abc, def, ghi'
var1=`echo $a | awk -F", " '{print RS $1}'`
echo "something: $var1"

which outputs
Code:
something
123

how can I tell awk not to put a newline between fields? I want it to output:
Code:
something: 123

# 2  
Old 10-12-2010
try using the printf() function without the newline char '\n'
# 3  
Old 10-12-2010
but after I echo "something: $var1" I want to put $var1 in a database, and the newline causes errors there, so I need remove the newline first.
# 4  
Old 10-12-2010
Hi,

I think it could be enough deleting 'RS'. Something like this:
Code:
var1=`echo $a | awk -F", " '{print $1}'`

Regards,
This User Gave Thanks to birei For This Post:
# 5  
Old 10-12-2010
yes, that worked, thank you Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

2. Shell Programming and Scripting

Removinf newline characters in first 62 fields

Hi All, I receive a | delimited text file containing 63 columns. There is no delimiter at the end of the 63rd field, instead there would be a newline character at the end of the text in 63rd column. I wanted to retain this newline character at the end of the 63rd column, as it is desired newline... (1 Reply)
Discussion started by: sagarparadkar
1 Replies

3. Shell Programming and Scripting

awk - compare 1st 15 fields of record with 20 fields

I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies

4. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

5. Shell Programming and Scripting

Join fields comparing 4 fields using awk

Hi All, I am looking for an awk script to do the following Join the fields together only if the first 4 fields are same. Can it be done with join function in awk?? a,b,c,d,8,,, a,b,c,d,,7,, a,b,c,d,,,9, a,b,p,e,8,,, a.b,p,e,,9,, a,b,p,z,,,,9 a,b,p,z,,8,, desired output: ... (1 Reply)
Discussion started by: aksijain
1 Replies

6. Shell Programming and Scripting

Newline between unequal record fields

Assume the following 5 records (field separator is a space): 0903 0903 0910 0910 0910 0910 0910 0910 0917 0917 0917 0917 0924 1001 1001 1001 1001 1008 1008 1008 1008 1015 1015 1015 1015 1022 1029 1029 1029 1029 1105 1105 1105 1105 1112 1112 1112 1112 1119 1126 1126 1126 1126 1203 1203 1203 1203... (8 Replies)
Discussion started by: tree
8 Replies

7. Shell Programming and Scripting

awk delete newline after other replacements

Dear All, could you please help me to remove \n characters after all other replacements have been done as in the code below: { #remove punctuation and starting whitespaces gsub("]"," "); $1=$1; } { #print lines containing 'whatever' if ($1=="whatever") {print} #print... (3 Replies)
Discussion started by: shivacoder
3 Replies

8. Shell Programming and Scripting

Newline characters in fields of a file

My source file is pipe delimeted file with 53 fields.In 33 rd column i am getting mutlple new line characters,dule to that record is breaking into multiple records. Note : here record delimter also \n sample Source file with 6 fields : 1234|abc| \nabcd \n bvd \n cde \n |678|890|900\n ... (6 Replies)
Discussion started by: lakshmi001
6 Replies

9. Shell Programming and Scripting

awk: printing newline with last column

I was trying to simplify this from what I'm actually doing, but I started getting even more confused so I gave up. Here is the content of my input file: Academic year,Term,Course name,Period,Last name,Nickname 2012-2013,First Semester,English 12,7th Period,Davis,Lucille When I do this: ... (3 Replies)
Discussion started by: nextyoyoma
3 Replies

10. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies
Login or Register to Ask a Question