Help with splitting fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with splitting fields
# 1  
Old 04-10-2013
Help with splitting fields

Hi. I want to put the first field to the end and the lines are of different number of fields. How should I do this with awk? Thanks.
# 2  
Old 04-10-2013
Have you made any attempt to solve this yourself? If so, what was it?

Regards,
Alister
# 3  
Old 04-11-2013
Hi, Alister
Thanks for your reply
I tried with
Code:
awk '{for(i=2;i<=NF;i++)print $i;print $1}'

but every field was output in a newline.
How can I rid of the newlines. Thanks

Dustin

Last edited by Franklin52; 04-11-2013 at 04:40 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 04-11-2013
You need to use printf in your code

Code:
awk '{for(i=2;i<=NF;i++)printf "%s ",$i;print $1}' infile

or

Code:
awk '{x=$1;sub(x,""); print $0,x}' infile

--ahamed

Last edited by ahamed101; 04-11-2013 at 04:35 AM..
This User Gave Thanks to ahamed101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. UNIX for Beginners Questions & Answers

Splitting the file based on two fields - Fixed length file

Hi , I am having a scenario where I need to split the file based on two field values. The file is a fixed length file. ex: AA0998703000000000000190510095350019500010005101980301 K 0998703000000000000190510095351019500020005101480 ... (4 Replies)
Discussion started by: saj
4 Replies

3. Shell Programming and Scripting

Splitting multiple fields of /usr/bin/id

Hi, Iv got the following input $id |grep uid uid=6090(dsiddiq) gid=1(staff) groups=4001(cdgrp) and Im using the below command to split the field to grab the numberical userid as well the alphabetical userid $id|awk -F'=' '{print $2}'|awk -F')' '{print $1}'|awk -F'(' '{print $1" "$2}'... (4 Replies)
Discussion started by: dsid
4 Replies

4. 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

5. Shell Programming and Scripting

File splitting according to the length of the fields

Hi All, I have two files: 1> Data file 2> info file which has field lengths and start position. Is there a way to create a comma delimited file according to the fields length and start position. Data file : R-0000017611N-00000350001095ANZU01 A00000017611N000000350001095ANZU02... (11 Replies)
Discussion started by: nua7
11 Replies

6. Shell Programming and Scripting

Splitting a filed into multiple fields using awk

Hi, I have a tab delimited file as below: AWA Divi DD01 None 1 2 Room AC 01-MAY-15 31-OCT-15 OT 01-MAY-15 31-OCT-15 CF 01-MAY-15 31-OCT-15 AW0 Beach DD02 None 1 2 Double AC 01-MAY-15 31-OCT-15 AD 01-MAY-15 31-OCT-15 The number of columns(fields) after 7th field is not fixed and... (3 Replies)
Discussion started by: Bobby_2000
3 Replies

7. Shell Programming and Scripting

Help in splitting Sub Fields and compare with other field

Hi All, We are trying to pull out data from below table, the table contains four fields and out of which last two fields are having sub-fields with delimiter $, we want to identify number "1" position in the 3rd field and from 4th field need to extract the information from the same position. ... (4 Replies)
Discussion started by: rramkrishnas
4 Replies

8. Shell Programming and Scripting

Splitting a column in two separate fields

for making a summary I have a CSV file which is transformed to .DAT. I have an AWK file which is supposing to do the mapping of the DAT file. The code from the AWK file is the one below. The content of the DAT file looks like this (tab separated): ODT AGE CDT CO SEX TIME VALUE COMMENT ... (1 Reply)
Discussion started by: grikoss
1 Replies

9. 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

10. Shell Programming and Scripting

Need help in splitting a line into fields in shell scripting

I have a line of more than 3000 bytes which will contain & as fields separator..I am using following awk command ..Its working but its not accepting the line more than 3000 bytes...Anyother alternate solution even in othe shell command also fine... awk -F '&' '{for( i=1; i<=NF; i++ ) print $i}'... (2 Replies)
Discussion started by: punithavel
2 Replies
Login or Register to Ask a Question