The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-08-2008
Registered User
 

Join Date: Jun 2007
Posts: 70
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.
Reply With Quote
Forum Sponsor
  #2  
Old 09-08-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Code:
echo "testfile1.dat.gpg_1EB85FB3" |awk 'BEGIN{FS="."; OFS="."}{print $1,$2}'
Reply With Quote
  #3  
Old 09-08-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
Or with sed:

Code:
echo "testfile1.dat.gpg_1EB85FB3" | sed 's/\(.*\)\..*/\1/'
Reply With Quote
  #4  
Old 09-08-2008
Registered User
 

Join Date: Jun 2007
Posts: 70
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.
Reply With Quote
  #5  
Old 09-08-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
Code:
awk -F ".gpg_" '{print $1, $2}'
Regards
Reply With Quote
  #6  
Old 09-08-2008
Registered User
 

Join Date: Aug 2007
Posts: 2
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
Reply With Quote
  #7  
Old 09-08-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
Works fine for me, try nawk or gawk.

Regards
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0