trying to strip the first 4 char. of a file out via commandline

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers trying to strip the first 4 char. of a file out via commandline
# 1  
Old 06-08-2001
trying to strip the first 4 char. of a filename out via commandline

im kind alost. i beleave its a sed command. but i cant seem to find it in my book. can someone point me in the write direction.

i know this is extreamly sloppy. but this is what i did untill i can figure out how to manipulate the filename namespace.

an ls on the directory where this would run would return 2 file names:


for i in `ls | awk -F"." '{ print $1 }'|awk -F"2" '{ print $2 }'`; do
                mv q162$i.* HBFULR$i`date +%Y%m%d%H%M%S`.DAT

Last edited by Optimus_P; 06-08-2001 at 07:14 PM..
# 2  
Old 06-11-2001
How about this:

for file in *
 newname=`echo $i | sed 's/^....//'`
 mv $file HBFULR${newname}`date +%Y%m%d%H%M%S`.dat

A little simpler...
# 3  
Old 06-12-2001
thank ya once again.

yeah i really need to brush up o learn some sed.

thanks for the pointers tho.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Load config file at commandline

Hello, This would be very basic question to most of you, but for me as a newbie it is an un-know. I would like to load a configuration file into memory before executing a specific command. For example: I have a config file that holds all the database connectivity information and I'd like to... (5 Replies)
Discussion started by: babyPen1985
5 Replies

2. Shell Programming and Scripting

How to add a line in every file with perl commandline?

Hi, i want to add a line at the beginning of every file in a directory. perl -i.bkp -p -e 'print "#include /verif/pdd1/exu/sxs/6sTest/reset/dfu/top_level.reset\n" if $. == 1' *.reset But this command is updating only the first file in the directory. I think this is because $. is not resetting... (3 Replies)
Discussion started by: twistedpair
3 Replies

3. Shell Programming and Scripting

How to print and append output of nawk script in commandline and as well into a file?

Hi All, I am working on nawk script, has the small function which prints the output on the screen.Am trying to print/append the same output in a file. Basically nawk script should print the output on the console/screen and as well it should write/append the same result to a file. script :... (3 Replies)
Discussion started by: Optimus81
3 Replies

4. Shell Programming and Scripting

strip csv file

Hi everyone, I hope someone can help me: i am trying to get some info from a csv file, after i awk the column i need , i made a selection and output it in a file. now i need to get a list from this file, but i stuck with some fields. basically i have a text file with next data: 3... (3 Replies)
Discussion started by: lostym
3 Replies

5. Shell Programming and Scripting

strip first 4 and last 2 lines from a file using perl

Hi I have a file from which i need to remove the first 4 and the last 2 lines.. i know how to do it with sed but i need to do it in a perl script.. can you please help me how to do that. Thanks (10 Replies)
Discussion started by: meghana
10 Replies

6. Shell Programming and Scripting

how to strip rows from a text file?

Can an expert kindly write an efficient Linux ksh script that will strip rows with no numbers from a text file? Supposing there are three rows that text file called text.txt : "field1","field2","field3",11,22,33,44 "field1","field2","field3",1,2,3,4 "field1","field2","field3",,,, The... (5 Replies)
Discussion started by: ihot
5 Replies

7. Shell Programming and Scripting

How to strip non numerical data out of file?

Hi, How can I remove all non numerical data from line, so I don't want to delete the line but to have only the numbers. e.g.: ######### 123 aaa124 125bbb 126 127 ######### So I want all the leading and trailing non numerical stuff(letters/white space/tabs anything else except... (10 Replies)
Discussion started by: Juha
10 Replies

8. UNIX for Dummies Questions & Answers

How to strip the contants from a file

Hi, I have some EDI data which 830, 862 and 997. Here is the sample data: ISA~00~ ~00~ ~ZZ~F159B ~ZZ~U1CAD ~051215~184 3~U~00200~000011432~0~P~< GS~FA~TC11A~U1CAD~051215~1843~000011432~X~002002 ST~997~0001 AK1~SH~1168 AK2~856~11680001 AK5~A... (2 Replies)
Discussion started by: isingh786
2 Replies

9. Shell Programming and Scripting

How to strip apostrophe from a file

I am trying to remove or replace various extraneous characters from a file so that subsequent processes work correctly. The characters that is giving me trouble is the apostrophe '. The command I 'm trying is sed 's/\'//g' ${IN_WRK_DIR}/file1 > ${IN_WRK_DIR}/file2 in a Korn script on HP... (8 Replies)
Discussion started by: aquimby
8 Replies
Login or Register to Ask a Question