another textprocessing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting another textprocessing
# 1  
Old 02-28-2011
another textprocessing

Hello, maybe too easy but I dont find the way....
I am processing (ksh) hourly a textfile with following content:
Code:
/inputfile/data/xxx/yyy/update/name_20110128.txt,123,LED,31....
/inputfile/data/xxx/yyy/update/name_20110127.txt,128,EPF,11....

the length of the row (after *.txt) is varying but before .txt is always the date.I would like to copy the date und add it just after update/ to get following structure:
Code:
/inputfile/data/xxx/yyy/update/20110128/name_20110128.txt,123,LED,31....
/inputfile/data/xxx/yyy/update/20110127/name_20110127.txt,128,EPF,11....

Does anyone has an idea/easy way how to solve this issue?

Thanks in advance....
# 2  
Old 02-28-2011
Code:
echo "/inputfile/data/xxx/yyy/update/name_20110128.txt,123,LED,31....
/inputfile/data/xxx/yyy/update/name_20110127.txt,128,EPF,11...." |sed -r 's/name_([0-9]+).txt/\1\/&/'
/inputfile/data/xxx/yyy/update/20110128/name_20110128.txt,123,LED,31....
/inputfile/data/xxx/yyy/update/20110127/name_20110127.txt,128,EPF,11....

# 3  
Old 02-28-2011
ok thanks for the reply.the name of the textfile is "input.txt". As I understand it correctly....you are searching for "name" and copy the numbers after. but "name" is also varying (red_20110127.txt, geen_20110127.txt)....
the only constant in each row is that the date is always before .txt and the date should be additionally always after "update"........sorry that my post was not too clear
# 4  
Old 02-28-2011
How about this,
Code:
 perl -nle 's/\/(\w+)(\d{8})/\/\2\/\1\2/;print $_;' inputfile

# 5  
Old 02-28-2011
Does this work for you?

Code:
sed -r 's/(update\/)([^0-9].*_)([0-9]+)(.txt)/\1\3\/\2\3\4/'

# 6  
Old 02-28-2011
Just a change to the solution suggested above

Code:
 
sed -r 's/.*_([0-9]+).txt/\1\/&/'

# 7  
Old 02-28-2011
I will test it...(can not do it at the moment)...on the first view I absolutley dont understand this part:
/\1\3\/\2\3\4

---------- Post updated at 03:01 PM ---------- Previous update was at 02:57 PM ----------

---------- Post updated at 03:04 PM ---------- Previous update was at 03:01 PM ----------

Quote:
Originally Posted by panyam
Just a change to the solution suggested above

Code:
 
sed -r 's/.*_([0-9]+).txt/\1\/&/'

thanks...but how do you put the date after update/....you just copy it?
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question