Text formatting question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text formatting question
# 1  
Old 05-24-2008
Text formatting question

How can i change the display of a text file containing

4980
167
187
4980
167
187
4980
167
180
4980
167
180
4980
167
179
4980
272
174
4980
347
174
4980
347
174

TO:

4980 167 187
4980 167 187
4980 167 180
4980 167 180
4980 167 179
4980 272 174
4980 347 174
4980 347 174

Thanks,
# 2  
Old 05-24-2008
One approach:

Code:
awk '{printf("%s",NR%3?$0" ":$0"\n")}' file

Regards
# 3  
Old 05-24-2008
Another one:

Code:
<file paste - - -

If you want a single space separator:


Code:
<file paste -d\  - - -

# 4  
Old 05-24-2008
Quote:
Originally Posted by Franklin52
One approach:

Code:
awk '{printf("%s",NR%3?$0" ":$0"\n")}' file

Regards
>>> awk '{printf("%s",NR%3?$0" ":$0"\n")}' /tmp/test2
awk: syntax error near line 1
awk: illegal statement near line 1

it's not working. but thanks any way

Quote:
Another one:

Code:

<file paste - - -

If you want a single space separator:


Code:

<file paste -d\ - - -
Thank you very much radoulov. it worked Smilie
# 5  
Old 05-24-2008
Quote:
Originally Posted by aliaa2a
>>> awk '{printf("%s",NR%3?$0" ":$0"\n")}' /tmp/test2
awk: syntax error near line 1
awk: illegal statement near line 1

it's not working. but thanks any way
[...]
You should use nawk or /usr/xpg4/bin/awk on Solaris.
# 6  
Old 05-24-2008
Quote:
Originally Posted by radoulov
You should use nawk or /usr/xpg4/bin/awk on Solaris.
with nawk it is working Smilie

Thanks for the help.

can you explain the command please ?
# 7  
Old 05-24-2008
Quote:
Originally Posted by radoulov
You should use nawk or /usr/xpg4/bin/awk on Solaris.
Thanks Radoulov.

Quote:
Originally Posted by aliaa2a
with nawk it is working Smilie

Thanks for the help.

can you explain the command please ?
Code:
 awk '{printf("%s",NR%3?$0" ":$0"\n")}' file

The printf statement uses a conditional operator:

Code:
 NR%3?$0" ":$0"\n"

NR is a built-in awk variable and it contains the linenumber.
Depends on the result of the mod operator (NR%3) it adds a space " " or a newline "\n" on the end of the line.
Thus on line 3, 6, 9 etc it prints a newline and on other lines a space after the line.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Formatting Question

Good Morning- I've been cloning a Solaris 9 SPARC machine using ufsrestoreand have successfully restored drive 0. Now I'm trying to set up the mirror drive. To label and format the new drive, I used#format -e ->select c0t1d0 ->label ->select SMI ->select no ->select no ->select yes and... (3 Replies)
Discussion started by: Stellaman1977
3 Replies

2. Post Here to Contact Site Administrators and Moderators

Text formatting

I know I've been away from the forums for past couple of months. But I am back now : ) I used to hit ctrl+B and ctrl+I after selecting the text to make text bold or italic respectively. (Pressing the keys would add and tags etc) However, that is not working anymore. Did I miss something? (13 Replies)
Discussion started by: clx
13 Replies

3. Shell Programming and Scripting

Help Me with the formatting of text

Hi, I am new to this forum; I need a help for my scripting problem. I have made a script in Unix which is extracting a report but the issue is that report is not in a proper format. Original Report Ex: Field 1....................... a b c d e f g Field 2............. @ID.@ID Field... (4 Replies)
Discussion started by: tush
4 Replies

4. Shell Programming and Scripting

Text formatting help

I have bunch of files with data's like below. archive.log.0104 ar0104_akl ar0731_rln ar0731_rsl M70148I need to compile all those files into a single file(.xls file) in the below format. 1st row is file name - should come in 1st column in excel In 2 - 4 row, all entries starts with... (13 Replies)
Discussion started by: vasanth_123
13 Replies

5. Shell Programming and Scripting

Help with Text formatting

I am generating the o/p as: BLANSWER 112747 112747 TBLQSTN 983 692 INITIATIVE 35 35 PAIGN 3122 3538 IGNCONTACT 90136 93534 IGNGROUP 27 27 AIGNSTEP 16899 20437 AIGNTYPE ... (1 Reply)
Discussion started by: karumudi7
1 Replies

6. Shell Programming and Scripting

Text formatting

A folder is having n number of files each file is having column names in it .Hence using below code . for file in /xxx/sss/* do filename=$( basename $file ) sed -e '1,2d; $d; /^*$/d; /selected\.$/d' ${file} | \ sed -e '1s/^/INSERT INTO '${filename}' VALUES (/; $!s/$/,/; $s/$/);/'... (6 Replies)
Discussion started by: rocking77
6 Replies

7. Shell Programming and Scripting

Text formatting

I have an input file as below. 1 Sanjib Gayen 2 Chetan Jadhav 3 Vijaykumar Uddi 4 Pinaki Sarkar I want to generate an output file as below. 1-Sanjib Gayen 2-Chetan Jadhav (4 Replies)
Discussion started by: R0H0N
4 Replies

8. Shell Programming and Scripting

text formatting

Hi, any idea input: mr.smith stvenson: /address #/tel no/ personal data profile. mrs.smith stevenson: /address #/tel no/occupation/ personal data profile. output: mr.smith stvenson address #: tel no: personal data profile. mrs.smith stevenson address #: tel no: occupation:... (7 Replies)
Discussion started by: kenshinhimura
7 Replies

9. UNIX for Dummies Questions & Answers

Text Formatting

I have a file like this with 1 lac lines. 1 2 3 4 5 6 7 8 9 0 I would like to format the above text file 1 2 3 4 5 6 7 8 9 0 (7 Replies)
Discussion started by: aravindj80
7 Replies

10. Shell Programming and Scripting

formatting text

Hi, I am having a file containing entries like: .iso.org.dod.internet.mgmt.mib-2.system.sysName.0 .iso.org.dod.internet.mgmt.mib-2.system.sysLocation.0 .iso.org.dod.internet.mgmt.mib-2.system.sysServices.0 .iso.org.dod.internet.mgmt.mib-2.system.sysORLastChange.0... (16 Replies)
Discussion started by: esham
16 Replies
Login or Register to Ask a Question