![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trim inside awk | subin_bala | Shell Programming and Scripting | 3 | 05-06-2008 09:51 AM |
| Trim issue | scorpio | Shell Programming and Scripting | 3 | 04-28-2008 12:19 PM |
| trim lines | melanie_pfefer | Shell Programming and Scripting | 6 | 03-26-2008 07:25 AM |
| trim file | tungaw2004 | UNIX for Dummies Questions & Answers | 1 | 09-15-2007 07:05 AM |
| trim letters | fed.linuxgossip | Shell Programming and Scripting | 10 | 05-15-2007 11:11 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Trim
Hello,
I am passing a filename to a script to draw parameters from it. However, I want to use part of the filename as a parameter. The filename is transfer_ccf_3731_10.sh but I only need the 3731_10 part of it. Is this possible? Any help or suggestions would be appreciated! Regards, J. |
|
||||
|
you can use bash's internal parameter expansion, check the bash man page, or tools like awk/sed.
eg awk Code:
# echo "transfer_ccf_3731_10.sh" | awk -F "_" '{print $3"_"substr($4,-1,2)}'
3731_10
Code:
# var="transfer_ccf_3731_10.sh"
# echo ${var%.sh}
transfer_ccf_3731_10
# echo ${var%.sh} | awk -F "_" '{print $3"_"$4}'
3731_10
|
|
|||||
|
Quote:
Code:
# var=transfer_ccf_3731_10.sh # OIFS="$IFS" # IFS="[_.]" # set -- $var # part="$3_$4" # IFS="$OIFS" # echo $part 3731_10 |
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|