Results 1 to 5 of 5
I am currently writing a script to compare a file list created over an FTP connection to a local directory.
I have cleaned the FTP file list up so that ...
- 07-04-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 3
prepending text conditionally
I am currently writing a script to compare a file list created over an FTP connection to a local directory.
I have cleaned the FTP file list up so that I just have a raw list of filenames however due to the directory structure employed (both locally and on the ftp site) I need to prepend each line with a directory name based on the first letter of the filename. For filenames that are numeric, the directory name is '123'. From this, I can perform a diff in order to give me a manifest of files missing locally to be downloaded using curl or wget.
Suggestions please?
- 07-04-2010 #2
awk could be used for this. something along the lines of
awk '$1 ~ /^[1-9].*/ {print "/directory/" $1}'
replacing $1 with whatever column the text is in. Awk breaks stuff down into 2 parts, a condition, and an action. The condition here is 'if column 1 starts with [1-9],' the action is {print /directory/column1}
it's kinda confusing at first, but mess around with it. You could create some complex stuff with it.New to the internet, technical forums, or the hacker / open source community??
Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html
RHCE for RHEL version 5
RHCT for RHEL version 4
- 07-04-2010 #3Just Joined!
- Join Date
- Jul 2010
- Posts
- 3
OK I think I get the idea - will have a play
- 07-04-2010 #4
you can run it from the command line as shown, but you can also run it as a script file. make a file like
then run (for example)Code:#!/bin/awk $1 ~ /^[1-9].*/ {print "/directory/" $1}
echo "123asdf" | awk --exec=filename
it will output/directory/123asdf
you can add more lines, and it will check each line of input text against all paterns. You can get a lot more advanced, but that is the limit of my awk knowledge.New to the internet, technical forums, or the hacker / open source community??
Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html
RHCE for RHEL version 5
RHCT for RHEL version 4
- 07-06-2010 #5Just Joined!
- Join Date
- Jul 2010
- Posts
- 3
Thanks - started playing with awk, but then somebody gave me this suggestion using sed
sed 's|.|/&/&|;s|^/[0-9]|/123|' infile
where infile is the file containing the list of files.


Reply With Quote
