Need to Add date on first position.Plz help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to Add date on first position.Plz help
# 15  
Old 10-06-2010
Quote:
Originally Posted by dprakash
...
if i have to remove the spaces also after header with spacess and tailor with spacess.
...plz sugest command..
...
Why not figure out all your problems and jot down all your questions in a single post, instead of asking them in installments ?

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 16  
Old 10-06-2010
Quote:
Originally Posted by durden_tyler
Why not figure out all your problems and jot down all your questions in a single post, instead of asking them in installments ?

tyler_durden
I totally agree with that!
# 17  
Old 10-06-2010
sed

Code:
sed "s/^/$(date +%Y%m%d)/" infile | tail -n+2 | head -n-1

# 18  
Old 10-06-2010
Quote:
Originally Posted by dprakash
Hi thanks its working perfectly..hi can you also plz modify this command:
Code:
awk 'NR==1 { date= substr($0,2,8)} NR> 1 { print date$0 }' source_file

to remove trailor record as shown below:
Code:
awk 'NR==1 { date= substr($0,2,8)} NR>1&&!/^[H|T]/ { print date$0 }' source_file

Guess you have several sessions with H2010XXXX to T0000xxxxx block, such as:

Code:
H20100928
D04041201609360677PC790010384I 
D04041203326357853PC790010645R 
D04041203602983265PC790010740R 
D04041208423493600PC790011258I 
T000000004 
H20100928
D04041201609360677PC790010384I 
D04041203326357853PC790010645R 
D04041203602983265PC790010740R 
D04041208423493600PC790011258I 
T000000004

then your code can be changed to:

Code:
awk '/^H/ { date=substr($0,2,8);next} !/^T/ { print date $0 }' source_file


Last edited by rdcwayx; 10-06-2010 at 08:40 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Identify the First Column Position in Second Column and add the position value

Identify the First Column Position in Second Column and add the position value in 3rd column. Sample data: a|c b|d c|a d|b e|e f|g g|f |h |i Expected Output: a|c|1 b|d|2 c|a|3 d|b|4 (6 Replies)
Discussion started by: BrahmaNaiduA
6 Replies

2. Shell Programming and Scripting

Plz Help in sorting the data on date basis

I have file a.txt having below data cat a.txt 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 IN 1514 0000764631 01-NOV-13 2.38.11.00.100089 IN 1514 0000856571 01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531 01-JUN-13 2.38.19.00.100000 IN 2698 0000764493... (5 Replies)
Discussion started by: ranabhavish
5 Replies

3. UNIX for Dummies Questions & Answers

Plz Help in sorting the data on date basis

I have file having below data 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 IN 1514 0000764631 01-NOV-13 2.38.11.00.100089 IN 1514 0000856571 01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531 01-JUN-13 2.38.19.00.100000 IN 2698 0000764493 01-JUL-13... (2 Replies)
Discussion started by: ranabhavish
2 Replies

4. Shell Programming and Scripting

Find and count unique date values in a file based on position

Hello, I need some sort of way to extract every date contained in a file, and count how many of those dates there are. Here are the specifics: The date format I'm looking for is mm/dd/yyyy I only need to look after line 45 in the file (that's where the data begins) The columns of... (2 Replies)
Discussion started by: ronan1219
2 Replies

5. Shell Programming and Scripting

Add '|' to data file on particular position

I have below scenario where i am getting a flat file but with some bad data incoming data format id|name|ind|crncy 123|xxx|y|usd 234|yy|n| 456|a|y90.5|vvv|gbp ----bad dataneed to cleanse the bad data above by adding a pipe '|' after 3rd column 'ind' if pipe '|' is not already there ... (1 Reply)
Discussion started by: rakesh5300
1 Replies

6. Shell Programming and Scripting

Need to check a file from a certain position and date onwards

Hi Guys, I need some advice please. My script is not grabbing information from a text file from a certain date correctly. It seems to be grabbing everying in the file, i know it is something simple but i have looked to hard and to long, to know what the issue is. Script awk '... (9 Replies)
Discussion started by: Junes
9 Replies

7. Shell Programming and Scripting

Need-To remove header/trailor and add-date-on first-postion-plz-help

Hi Friends thanks a lot....for ur replies its worked fine...i have one more question.. if i need to remove trailor (T000000004 ) as shown below file also with header.Plz help thanks Source file: H20100928 D04041201609360677PC790010384I D04041203326357853PC790010645R ... (1 Reply)
Discussion started by: dprakash
1 Replies

8. Shell Programming and Scripting

How to add a column numbers at a particular position?

Problem discription: I have many files which contain the same lines. for instance, (15 lines) file1 ..last column add by hand arbitrarily. 1.78116800 0.68396600 0.00061900 0.47641600 -0.49794500 -0.00024000 -1.70662800 0.29577100 0.67863600 -1.70647600 0.29654600 ... (9 Replies)
Discussion started by: liuzhencc
9 Replies

9. UNIX for Advanced & Expert Users

Friendz.. plz help me on this date function.

:confused: Hi there. Hi frndz, I have to script a shell in such a way that by giving the current date, it should give the previous saturday date and next sunday date as output. eg: Input - 01-01-2008 O/p - last saturady- 30-12-2007(ddmmyy) Next Sunday- 05-01-2008 ... (14 Replies)
Discussion started by: psn123
14 Replies

10. UNIX for Dummies Questions & Answers

plz Help How should I configure cc compiler output file plz help???

i.e configuration of C compiler :confused: (4 Replies)
Discussion started by: atiato
4 Replies
Login or Register to Ask a Question