Show file to new format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Show file to new format
# 1  
Old 12-11-2008
Show file to new format

Hi all

If my text file as follow:

group size time file
other 58585739 2008 test1.csv
other 122 2008 testcsv.sh
other 164 19:28 testexplain.sh
other 29132428 2008 testq.csv
other 104 21:02 testshell.sh
other 792 21:39 xxx.txt


I need to show file to new format as follow:

group size time file
----------------------------------------------------
other 58585739 2008 test1.csv
other 122 2008 testcsv.sh
other 164 19:28 testexplain.sh
other 29132428 2008 testq.csv
other 104 21:02 testshell.sh
other 792 21:39 xxx.txt

please suggest me how to do this?

Regards
Almanto

Last edited by almanto; 12-11-2008 at 05:15 PM..
# 2  
Old 12-11-2008
Hammer & Screwdriver One way to format

Code:
> head -1 file111; echo "-----------------------------" ;tail +2 file111
group size time file
-----------------------------
other 58585739 2008 test1.csv
other 122 2008 testcsv.sh
other 164 19:28 testexplain.sh
other 29132428 2008 testq.csv
other 104 21:02 testshell.sh
other 792 21:39 xxx.txt

# 3  
Old 12-11-2008
.........
# 4  
Old 12-11-2008
this will also work
Code:
awk 'NR==1{print $0"\n----------------------------------"};NR>1{print $0}' filename

# 5  
Old 12-11-2008
Quote:
Originally Posted by almanto
Hi all

If my text file as follow:

group size time file
other 58585739 2008 test1.csv
other 122 2008 testcsv.sh
other 164 19:28 testexplain.sh
other 29132428 2008 testq.csv
other 104 21:02 testshell.sh
other 792 21:39 xxx.txt


I need to show file to new format as follow:
Code:
group size            time     file
---------------------------------------
other 58585739    2008     test1.csv
other 122            2008     testcsv.sh
other 164            19:28    testexplain.sh
other 29132428    2008     testq.csv
other 104            21:02    testshell.sh
other 792            21:39    xxx.txt

please suggest me how to do this?

Since you didn't put [code] tags around your desired format, it wasn't clear that you wanted spacing added to the lines, so this would work:

Code:
{
 read line
 printf "%s\n" "$line" "---------------------------------------"
 cat
} < filename

What I think you really want is:

Code:
awk '{ printf "%-6s %-10s %-6s %s\n", $1, $2, $3, $4 }
NR == 1 { print "---------------------------------------" }
' < filename

# 6  
Old 12-11-2008
Thanks very much ,cfajohnson
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Show the string in date format

Hello guys. how can print the: 20140206 like Fri, Feb 6, 2015 Thank you. (4 Replies)
Discussion started by: Ymir
4 Replies

2. Shell Programming and Scripting

Need help to format one txt file to required format

Hello Everyone, I have one source file which is genarated by SAP in different format(Which I've never seen). I need to convert that file to required format and I need to read this target file from Datastage to use this in my Jobs. So I do not have any other options except to use Unix script to... (4 Replies)
Discussion started by: Prathyu
4 Replies

3. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

4. Shell Programming and Scripting

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (2 Replies)
Discussion started by: Samtel
2 Replies

5. UNIX for Dummies Questions & Answers

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (1 Reply)
Discussion started by: Samtel
1 Replies

6. Shell Programming and Scripting

Show file to new format

Hi all If my text file as follow: group size time file other 58585739 2008 test1.csv other 122 2008 testcsv.sh other 164 19:28 testexplain.sh other 29132428 2008 testq.csv other 104 21:02 testshell.sh other 792 21:39 xxx.txt I need to show file to new format as follow: group... (1 Reply)
Discussion started by: almanto
1 Replies

7. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

8. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

9. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

10. Shell Programming and Scripting

Want to show data in tabel format

Hello , I need help to show data in table format i have 2 files A and B A files contains 2 coulmns $1 $2 Test 34 Test1 35 Test4 78 Test6 89 B file contains 2 coulmns $3 $4 Test 65 Test4 67 Test6 98 (10 Replies)
Discussion started by: getdpg
10 Replies
Login or Register to Ask a Question