|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help Using AWK Script
Hi all I have been researching awk and in my script testing I cant get awk to work in a script. I have a file that I need to move and rename into the new directory. I am pretty new to shell scripting. So any links or pointers to what I am trying to accomplish would be highly appreciated!!!! The file I will be getting is based in this format “Recipient_<ClientId>_<CampaignId>_<PSIJobCode>_<CPACId>.<BatchNumber>.pdf” I need to pull out the <CampaignId> and the <CPACId> of the file to rename the file to <CPACId> and put the file into a newly created directory with the <CampaignId> as the name. I have been trying something like this to pull out the information but it doesn't seem to rename the file Code:
new_name=`awk -F"_" '{print $5}' $fileName`
CampaignId=`awk -F"_" '{print $3}' $fileName
mv $fileName $new_name |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
There's probably more efficient ways than running two entire instances of awk to process one file name.
What's your system? What's your shell? |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
I'm not sure but I am finding out. I know its a Lunix box and #!/bin/sh is on top of other scripts that are working
|
|
#4
|
|||
|
|||
|
LUnix is an experimental operating system for the commodore 64. Did you perhaps mean Linux?
If so there are many linux distributions. Try 'uname -a' to find out which. Or perhaps you mean UNIX? Or just meant that you really don't know. In any case, try 'uname -a' to find out which. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
LOL yes Linux.
I did find out that the System is a CentOS 5 box... default shell is BASH. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Then you can do this: Code:
#!/bin/bash
IFS="_." read RECIP CLIENTID CAMPAIGNID PSIJOBCODE CPACID BATCHNUMBER EXTENSION <<<"${FILENAME}"
mkdir -p $CAMPAIGNID
echo mv "$FILENAME" "${CAMPAIGNID}/${CPACID}"Remove the 'echo' once you're sure it does what you want. |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with shell script - Calling a script through script | Siddheshk | Shell Programming and Scripting | 0 | 04-18-2011 05:14 AM |
| create a shell script that calls another script and and an awk script | magikminox | Shell Programming and Scripting | 0 | 06-26-2008 02:50 AM |
|
|