![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 | Thread Starter | Forum | Replies | Last Post |
| check for a particular character inside a file and substitute with a given character? | karthikprasathk | AIX | 1 | 07-01-2008 12:29 AM |
| read a variable character by character, substitute characters with something else | vipervenom25 | UNIX for Dummies Questions & Answers | 2 | 06-06-2008 12:18 PM |
| How can I use double character delimiter in the cut command | AshishK | UNIX for Advanced & Expert Users | 1 | 10-07-2007 12:36 PM |
| Multi User Multi Task | Reza Nazarian | UNIX for Dummies Questions & Answers | 6 | 04-13-2006 06:23 AM |
| multi-file multi-edit | kielitaide | UNIX for Dummies Questions & Answers | 12 | 06-28-2001 12:12 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
multi character delimiter
Hi All
I have to encrypt files and add a suffix ".gpg_<key used>" to it For example if the file name is test.dat after encryption the file name will be test.dat.gpg_X005 (here X005 is the key). I want to decrypt the file later using that key and the original file name.both of them should be picked up from the encrypted file name in unix file system. The script i am using echo "testfile1.dat.gpg_1EB85FB3" |awk 'BEGIN{FS=".gpg_"}{print $1}' and getting the output as testfile1 Where as I want the output to be testfile1.dat I think the field separator is not working properly when used as multicharacter. Please help me writing the above script. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
echo "testfile1.dat.gpg_1EB85FB3" |awk 'BEGIN{FS="."; OFS="."}{print $1,$2}'
|
|
#3
|
|||
|
|||
|
Or with sed:
Code:
echo "testfile1.dat.gpg_1EB85FB3" | sed 's/\(.*\)\..*/\1/' |
|
#4
|
|||
|
|||
|
Thanks for your quick response.
I want the original file name and the key used for encryption. The file name and the key can be anything and it needs to be picked from the file specified for e.g. if the file name is testfile1.dat.gpg_1EB85FB3 Then the original file name is testfile1.dat and the key is 1EB85FB3 . Is there a way I can distinguish it as two fields by taking .gpg_ as the fiels separator? Thanks. |
|
#5
|
|||
|
|||
|
Code:
awk -F ".gpg_" '{print $1, $2}'
|
|
#6
|
|||
|
|||
|
Hi Franklin-
Using the above command awk takes only . as the field separator and not the whole .gpg_. Is there a way to provide multi character delimiter. Regards, Pradeep |
|
#7
|
|||
|
|||
|
Works fine for me, try nawk or gawk.
Regards |
|||
| Google The UNIX and Linux Forums |