format change


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting format change
# 1  
Old 05-18-2010
format change

I have a text file sample.txt which contains some details like

Code:
Order 
9001
Item Code
34
Quantity
4
Entry Date 
2009-04-23
Ordered by 
Ram


Order 
9002
Item Code
34
Quantity
3
Entry Date 
2010-04-23
Ordered by 
Ram

Order 
9003
Item Code
27
Quantity
4
Entry Date 
2010-04-23
Ordered by 
Ram

Order 
9004
Item Code
13
Quantity
7
Entry Date 
2008-04-23
Ordered by 
Ram


on reading this file my file format should be as follows

Code:
Order	Item Code	Quantity	Entry Date	Ordered by 
9001	34		4		2009-04-23	Ram
9002	34		6		2010-05-02	Ram
9003	27		4		2008-04-23	Ram
9004	13		7		2008-04-23	Ram

# 2  
Old 05-19-2010
Code:
$> cat mach*
awk '
        BEGIN{
                printf("%-8s%-15s%-15s%-15s%-15s\n", "Order","Item Code","Quantity","Entry Date","Ordered by")
        }
        {printf("%-8s%-15s%-15s%-15s%-15s\n", $2,$4,$6,$8,$10)}
' FS="\n" RS="\n\n+" infile
$>
$> ./mach*
Order   Item Code      Quantity       Entry Date     Ordered by
9001    34             4              2009-04-23     Ram
9002    34             3              2010-04-23     Ram
9003    27             4              2010-04-23     Ram
9004    13             7              2008-04-23     Ram

This User Gave Thanks to zaxxon 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

Change the format of the strings

I have Input file as below 1 a 1 b 1 c 2 d 2 e 2 f I want below output as below. 1 a,b,c 2 c,d,e Pls suggest how can i do it. (1 Reply)
Discussion started by: millan
1 Replies

2. Shell Programming and Scripting

Change name format

I am trying to use either awk or sed to make names like J. A. Smith and J.A. Martin Smith become JA Smith and JA Martin SmithThe code should concatenate abbreviated letters that have a dot after them. I have only been able to do this: echo $name | sed 's/\.\ //g'But that concatenates the... (3 Replies)
Discussion started by: locoroco
3 Replies

3. Shell Programming and Scripting

Change the date format

Hi all, I have a file that every line starts with the date and time. The format is like YYYYMMDDHHMM and I woulk like to change it to MM/DD/YY<space>HH:MM. I tried to figure out a way to do it with sed, but I don't know how I could reorganize the digits of the first format. Does anyone have any... (1 Reply)
Discussion started by: geovas
1 Replies

4. Shell Programming and Scripting

Format change

I wish to convert the following in shell. Help me SED or AWK ID= 12345,23456,67859 , 90225 , 67583 I can extract the right hand side of "=" using cut command "cut -d "=" -f2 after extracting that right side i would need like this '12345','23456','67859','90225','67583' 1 ) the... (2 Replies)
Discussion started by: ilugopal
2 Replies

5. Shell Programming and Scripting

change the output format

when i run the following command db2 list tablespaces Tablespaces for Current Database Tablespace ID = 0 Name = SYSCATSPACE State = 0x0000 Tablespace ID ... (3 Replies)
Discussion started by: lazydev
3 Replies

6. Shell Programming and Scripting

Change date format

Hi guys, I have a text file with lots of lines like this: MCOGT23R27815 27/07/07 27/05/09 SO733AM0235 30/11/07 30/11/10 NL123403N 04/03/08 04/03/11 0747AM7474 04/04/08 04/04/11 I want to change each line so the date format looks like this: MCOGT23R27815 07/07/27 09/05/27 ... (7 Replies)
Discussion started by: Tornado
7 Replies

7. Solaris

change date format

dear members, ls -l drwxr-xr-x 40 root sys 1024 Jul 11 22:19 usr drwxr-xr-x 43 root sys 1024 Feb 1 2009 var i am using solaris 10 is that possibe to do drwxr-xr-x 40 root sys 1024 25-08-2009 22:19 usr drwxr-xr-x 43 root sys ... (4 Replies)
Discussion started by: hosney00ux
4 Replies

8. Shell Programming and Scripting

How to Change the Format of a Date

Hi All, this is my second post, last post reply was very helpful. I have a data that has date in DD/MM/YYYY (07/11/2008) format i want to replace the backslash by a dot(.) so that my awk script can read it inside the C shell script that i have written. i want to change 07/11/2008 to... (3 Replies)
Discussion started by: asirohi
3 Replies

9. UNIX for Dummies Questions & Answers

How to change it to the date format

Hi, I want to know how to change this string to date format 20061102122042 to 02-11-2006 12:20:42 or 02-Nov-2006 12:20:42 Please let me know at the earliest.Thanks in advance. Regards, Preetham R. (3 Replies)
Discussion started by: preethgideon
3 Replies

10. Shell Programming and Scripting

change the empty function from the old format to the new format

I have about 300 files which has the function getDBBackend(). How to write a program to change the empty function from the old format to the new format? Old empty function format are either: function getDBBackend() { // Not available } // getDBBackend or: function... (0 Replies)
Discussion started by: powah
0 Replies
Login or Register to Ask a Question