Sponsored Content
Top Forums Shell Programming and Scripting Create new file by searching another file Post 42540 by Simerian on Thursday 30th of October 2003 03:56:04 PM
Old 10-30-2003
Without further information regarding the problem, it is difficult to determine the amount of processing required for each field in turn. As an example, there may be a need to reformat certain fields. Using the original code as an indicator, I would suggest the following...

Assuming an input file with records of 2 fields:

e-mail john.doe@domain.com
forename John
middlename Franklin
surname Doe
END

e-mail mary.doe@domain.com
forename Mary
middlename Doris
surname Doe
END

etc

Code:
awk '

/^e-mail/ { Key=1 }
/^forename/ { Key=2 }
/^middlename/ { Key=3 }
/^surname/ { Key=4 }

Key > 0 {
   Data[Key]=$2
   Key=0
}

/^END/ {
   for (c=1; c < 4; c++) {
      printf "%s,",Data[c]
   }
   printf "%s\n",Data[4]

   for (c in Data) delete Data[c]
}
' inputfile.txt >outputfile.txt

...this replicates what I believe Leo is trying to achieve. It appears to be about creating a csv file of fields rather than just banging each record out "as is". Wouldn't you say? Each field can be dealt with in turn to allow field specific processing.

The END entry is just for triggering the output, although the last field name could be used (i.e. surname) if its ordinal position is always last.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append a field to the end of each line of a file based on searching another file.

Hi All, I have two comma separated value(CSV) files, say FileA and FileB. The contents looks like that shown below. FileA EmpNo,Name,Age,Sex, 1000,ABC,23,M, 1001,DES,24,F, ... (2 Replies)
Discussion started by: ultimate
2 Replies

2. Shell Programming and Scripting

searching a log file and appending to a .txt file

I'm new to shell scripting and am writing a script to help me log the free memory and hd space on a server. As of now, the script just runs 'df -h' and appends the output to a file and then runs 'top' and appends the output to a log file. What I want to do, is have the script also search the... (3 Replies)
Discussion started by: enator45
3 Replies

3. Shell Programming and Scripting

create file as variable for searching point

Hi Friends, I need expert help:), I have bellow script that function for searching string in multiple file, the script is working well. but I thing it still can be optimize since so many repetition in bellow command, where string that I marked BOLD italic is clue for what I am looking for... (2 Replies)
Discussion started by: budi.mulya
2 Replies

4. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

5. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

6. Shell Programming and Scripting

Help in searching a particular string in a file name (not inside the file contents)

Dear Unix Gurus, I am new to shell scripting and in the process of learing. I am trying to find whether a file name has today's date in MMDDYYYY format. I am using the following code and it doesn't seem like working. #!/usr/bin/ksh today=$(date '+%m%d%Y') echo today: $today file=`find... (4 Replies)
Discussion started by: shankar1dada
4 Replies

7. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

8. Shell Programming and Scripting

Searching a file inside a .tar.gz file by date

Hi, I would like to ask if there is a way to search for a file inside a .tar.gz file without extracting it? If there is, is there a way to search for that file by date? Thanks! (4 Replies)
Discussion started by: erin00
4 Replies

9. Shell Programming and Scripting

Searching the content of one file using the search key of another file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search key is... (3 Replies)
Discussion started by: csim_mohan
3 Replies
OPIEKEYS(5)                                                     File Formats Manual                                                    OPIEKEYS(5)

NAME
[/etc/]opiekeys - OPIE database of user key information DESCRIPTION
The opiekeys file contains user information used by the OPIE software to authenticate users. The opiekeys file is backwards compatible with the S/Key /etc/skeykeys database file, but only if the hashing algorithm (MD4 and MD5) is the same between S/Key and OPIE (i.e., MD5 OPIE cannot use MD4 S/Key keys). The opiekeys file consists of six fields separated by spaces (tabs are properly interpreted, but spaces should be used instead) as follows: Field Description name User's login name. sequence User's sequence number. seed User's seed. key User's last response (hex). date Last change date. time Last change time. SEE ALSO
opie(4), opiekeys(5), opiepasswd(1), opieinfo(1), opiesu(1), opielogin(1), opieftpd(8) AUTHOR
Bellcore's S/Key was written by Phil Karn, Neil M. Haller, and John S. Walden of Bellcore. OPIE was created at NRL by Randall Atkinson, Dan McDonald, and Craig Metz. S/Key is a trademark of Bell Communications Research (Bellcore). CONTACT
OPIE is discussed on the Bellcore "S/Key Users" mailing list. To join, send an email request to: skey-users-request@thumper.bellcore.com 7th Edition January 10, 1995 OPIEKEYS(5)
All times are GMT -4. The time now is 04:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy