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
# 8  
Old 10-06-2010
And Perl -

Code:
$
$ perl -lne '$.==1 ? do{/.(.*)/ and $x=$1} : print "$x$_"' f29
20100928D04041201609360677PC790010384I
20100928D04041203326357853PC790010645R
20100928D04041203602983265PC790010740R
20100928D04041208423493600PC790011258I
$
$ perl -lne '$.==1 ? $x=substr($_,1) : print "$x$_"' f29
20100928D04041201609360677PC790010384I
20100928D04041203326357853PC790010645R
20100928D04041203602983265PC790010740R
20100928D04041208423493600PC790011258I
$

tyler_durden
# 9  
Old 10-06-2010
need-add-date-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
D04041203602983265PC790010740R
D04041208423493600PC790011258I
T000000004


Output File should be as :
20100928D04041201609360677PC790010384I
20100928D04041203326357853PC790010645R
20100928D04041203602983265PC790010740R
20100928D04041208423493600PC790011258I


---------- Post updated at 08:25 AM ---------- Previous update was at 08:25 AM ----------

--------------------------------------------------------------------------------

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
D04041203602983265PC790010740R
D04041208423493600PC790011258I
T000000004

Output File should be as :
20100928D04041201609360677PC790010384I
20100928D04041203326357853PC790010645R
20100928D04041203602983265PC790010740R
20100928D04041208423493600PC790011258I
# 10  
Old 10-06-2010
Code:
awk 'NR==1{s=substr($0,2);next}p{print p}{p=s $0}' file

This User Gave Thanks to Franklin52 For This Post:
# 11  
Old 10-06-2010
Code:
$
$ cat f29
H20100928
D04041201609360677PC790010384I
D04041203326357853PC790010645R
D04041203602983265PC790010740R
D04041208423493600PC790011258I
T000000004
$
$
$ awk 'NR==1{x=$0; sub(/^H/,"",x)} NR>1 && /^[^T]/{print x$0}' f29
20100928D04041201609360677PC790010384I
20100928D04041203326357853PC790010645R
20100928D04041203602983265PC790010740R
20100928D04041208423493600PC790011258I
$
$ perl -lne '$.==1 ? do{/.(.*)/ and $x=$1} : print "$x$_" if /^[^T]/' f29
20100928D04041201609360677PC790010384I
20100928D04041203326357853PC790010645R
20100928D04041203602983265PC790010740R
20100928D04041208423493600PC790011258I
$
$ perl -lne '$.==1 ? $x=substr($_,1) : print "$x$_" if /^[^T]/' f29
20100928D04041201609360677PC790010384I
20100928D04041203326357853PC790010645R
20100928D04041203602983265PC790010740R
20100928D04041208423493600PC790011258I
$
$

Note that these one-liners prefix the date only for those lines that are other than the first as well as do not start with "T". They aren't specifically looking for (in order to avoid) the last line that starts with "T".

tyler_durden
# 12  
Old 10-06-2010
Code:
$ ruby -ne 'h=$_[1..-1].chomp! if $.==1; print "#{h}#{$_}" if $.>1 and not $_[/^T/]' file

# 13  
Old 10-06-2010
Hi thanks its working perfectly..hi can you also plz modify this command:
awk 'NR==1 { date= substr($0,2,8)} NR> 1 { print date$0 }' source_file
to remove trailor record as shown below:

H20100928
D04041201609360677PC790010384I
D04041203326357853PC790010645R
D04041203602983265PC790010740R
D04041208423493600PC790011258I
T000000004

Output File should be as :
20100928D04041201609360677PC790010384I
20100928D04041203326357853PC790010645R
20100928D04041203602983265PC790010740R
20100928D04041208423493600PC790011258I

---------- Post updated at 09:57 AM ---------- Previous update was at 09:53 AM ----------

if i have to remove the spaces also after header with spacess and tailor with spacess.

---------- Post updated at 09:57 AM ---------- Previous update was at 09:57 AM ----------

plz sugest command..
thanks
in advance
# 14  
Old 10-06-2010
Code:
awk '/^H/{s=substr($0,2)}/^D/{print s $0}' file

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