multi character delimiter


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers multi character delimiter
# 1  
Old 09-08-2008
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.
# 2  
Old 09-08-2008
Code:
echo "testfile1.dat.gpg_1EB85FB3" |awk 'BEGIN{FS="."; OFS="."}{print $1,$2}'

# 3  
Old 09-08-2008
Or with sed:

Code:
echo "testfile1.dat.gpg_1EB85FB3" | sed 's/\(.*\)\..*/\1/'

# 4  
Old 09-08-2008
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  
Old 09-08-2008
Code:
awk -F ".gpg_" '{print $1, $2}'

Regards
# 6  
Old 09-08-2008
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  
Old 09-08-2008
Works fine for me, try nawk or gawk.

Regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. UNIX for Dummies Questions & Answers

How to replace particular occurrence of character in between a delimiter?

Hi, Hi, I have a file with following format 1|" "text " around " |" fire "guest"|" " 2| "xyz"" | "no guest"|"3" 3| """ test3""| "one" guest"|"4" My requirement is to replace all occurrences of " to ' which are occurring between |" "|delimiter so my output should look like this 1|"... (3 Replies)
Discussion started by: H_bansal
3 Replies

4. Shell Programming and Scripting

Cutting a string using more than one character as delimiter

Hi , I have a set of files in a folder which i need to cut in to two parts.... Sample files touch AE_JUNFOR_2014_MTD_2013-05-30-03-30-02.TXT touch AE_JUNFOR_2014_YTD_2013-05-30-03-30-02.TXT touch temp_AE_JUNFOR_2014_MTD_2013-05-30-03-30-02.TXT touch... (4 Replies)
Discussion started by: chillblue
4 Replies

5. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

6. Shell Programming and Scripting

[Solved] SED - Bash - Inserting multi Tab character in the command

Hello. I am using : sed -i -e '/§name_script§/a#'"${MY_TAB11}"'# \ #'"${MY_TAB1}"'The Standard way'"${MY_TAB7}"'# \ #'"${MY_TAB1}"'==============='"${MY_TAB7}"'# \ ' "$CUR_FILE" Is there a better way to define "MY_TAB7","MY_TAB11" in other way than : MY_TAB1=$'\t' MY_TAB2=${MY_TAB1}$'\t'... (2 Replies)
Discussion started by: jcdole
2 Replies

7. Shell Programming and Scripting

Inserting newline in front of multi-character string

I'm working with a large file with multiple records, each record begins with ISA. The issue is, sometimes ISA is at the start of the line, sometimes it's in the middle of the line. So before I can csplit my main file into multiple records, I have to get each record header onto its own line. ... (7 Replies)
Discussion started by: verge
7 Replies

8. Shell Programming and Scripting

awk with multiple character delimiter

Hi all, I'm trying to split fields separated by multiple characters : Here's the string : "toto"||"ta|ta"||"titi" Here's what I want : "toto"||"ta|ta" I tried several ways, but it seems that my delimiter || is not working : echo "\"toto\"||\"ta|ta\"||\"titi\"" | awk 'BEGIN... (4 Replies)
Discussion started by: popawu
4 Replies

9. UNIX for Dummies Questions & Answers

find and remove rows from file where multi occurrences of character found

I have a '~' delimited file of 6 - 7 million rows. Each row should contain 13 columns delimited by 12 ~'s. Where there are 13 tildes, the row needs to be removed. Each row contains alphanumeric data and occasionally a ~ ends up in a descriptive field and therefore acts as a delimiter, resulting in... (1 Reply)
Discussion started by: kpd
1 Replies

10. UNIX for Advanced & Expert Users

How can I use double character delimiter in the cut command

Hi All, Can the cut command have double character delimiter? If yes, how can we use it. if my data file contains : apple || mango || grapes i used cut -f1 -d"||" filename but got an error. Plz help.... Thanks. (1 Reply)
Discussion started by: AshishK
1 Replies
Login or Register to Ask a Question