Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sed/Awk Question

Status
Not open for further replies.

moreCA

Programmer
Feb 11, 2003
68
US
I have a file name FSR350B050112.dly. That is how it comes to me in UNIX. I need to strip off the 050112 to make the file just say FSR350B.dly and then I will do some other manipulation from there but I just do not know how to get that piece off.

Thank you...
 
[your mileage may vary]
This assumes that you drop SIX characters.

echo 'FSR350B050112.dly' | sed -e 's/^\(.*\)\(......\)\.dly$/\1.dly/g'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
its pretty "cut" and dry if the name is always the same except for the date.

echo "FSR350B050112.dly" | cut -c1-7,14-
 
To rename all the files in the current directory (ksh like):
for dly in *.dly; do
case "$dly" in *[0-9][0-9][0-9][0-9][0-9][0-9].dly)
mv "$dly" $(echo "$dly" | sed 's!......\.dly!.dly!')
esac
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV....when I use your lines of code...only the last files changes. I do have several files that need to be changed to that format but only the last on is actually changing?? Can you help??

Thank you....
 
Vergersh99....in your case how would you do it for multiple files? I am trying to work out the best case for this problem.

Thank you.....
 
for dly in *[0-9][0-9][0-9][0-9][0-9][0-9].dly; do
mv "$dly" $(echo "$dly" | sed 's!......\.dly!.dly!')
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Ok.....one more question and I think I will be out of ya'lls hair. I used the command `echo $fname | sed -e 's/^\(.*\)\(......\)\.dly$/\1.dly/g'` to take care of the first issue. Now I need to use that same command along the same lines to get rid of the date plus everything else to the right of it. As in FSR350B050112.dly needs to be just FSR350B so I can then add a different piece to the end of it. Thank you for all of the help.
 
for dly in *[0-9][0-9][0-9][0-9][0-9][0-9].dly; do
f=$(echo "$dly" | sed 's!......\.dly!!')
echo "$dly --> $f"
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top