Sponsored Content
Top Forums Shell Programming and Scripting How to Populate field in File with it's manipulated Filename? Post 302746333 by pamu on Wednesday 19th of December 2012 06:59:49 AM
Old 12-19-2012
Try

Code:
$ cat file
"Terr","TerrName","Dist","DistName","REGION","RgnName","BCName"
"A0010000","Abilene TX A 1","A0010957","Dallas TX","A0010998","West","US HEADQUARTERS"
"A0010001","Akron OH A 1","A0010954","Cleveland OH","A0010997","Central","US HEADQUARTERS"
"A0010002","Alaska AK A 1","A0010991","Seattle WA","A0010998","West","US HEADQUARTERS"

Code:
$ awk 'BEGIN{FS=",";OFS="|";}
NR==1{s=FILENAME;n=split(s,P,"[_.]")}
NR>1{gsub("\"","");$NF= OFS $NF OFS P[n-1];print}'  DCIA_GEOG_DATA_OCEAN.TXT

A0010000|Abilene TX A 1|A0010957|Dallas TX|A0010998|West||US HEADQUARTERS|OCEAN
A0010001|Akron OH A 1|A0010954|Cleveland OH|A0010997|Central||US HEADQUARTERS|OCEAN
A0010002|Alaska AK A 1|A0010991|Seattle WA|A0010998|West||US HEADQUARTERS|OCEAN

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using the getline to populate an array from a file

Hello, I am trying to use the awk getline command to populate an array from a flat file. Has anyone done this before? So we have file1: a b c d I want to create an array like index that contains these four elements (8 Replies)
Discussion started by: penfold
8 Replies

2. Shell Programming and Scripting

how to include field in the output filename of awk

Im using awk and I want the output filename to contain the first field of the input file. Ex. 1 dddd wwwww 1 eeeee wwww 1 wwww eerrrr 2 eeee eeeeee I want the output files to be xxx1 and xxx2 Thank you (4 Replies)
Discussion started by: yahyaaa
4 Replies

3. Shell Programming and Scripting

shellscript.query Oracle table..populate in a text file

Hi Guys, I'm new to this forum as well as to UNIX shell scripting. I'm looking for a shellscript to query an Oracle database table and populate the result set of the query in a text file. Could you someone help me out with a sample code? Thanks, Bhagat (7 Replies)
Discussion started by: bhagat.singh-j
7 Replies

4. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

5. Shell Programming and Scripting

Unable to populate subject field of the email while using sendmail

Hi, Can anyone kindly provide some information about how to populate the subject field of the email while using the sendmail utility ? Itried the following command line argument : echo -e "Body of the email" | /usr/lib/sendmail -f from@from.com -t to@to.com -s " Subject of the email" ... (4 Replies)
Discussion started by: sdiptanil
4 Replies

6. Shell Programming and Scripting

Appending 1st field in a file into 2nd field in another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (0 Replies)
Discussion started by: amurib
0 Replies

7. Shell Programming and Scripting

Append 1st field from a file into 2nd field of another file

Hi, I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much. Actually, I'm in short with time. So I had to post my case. Hoping that you can help. I have 2 files, FILE1 ... (1 Reply)
Discussion started by: amurib
1 Replies

8. Shell Programming and Scripting

how to get filename along with its first field

hi, i have some 37 files having a file name pattern 'stg*' which are tilde delimited files. the requirement is i need to fetch two columns field1:filename field2:first field of each file.... for example if i have a file like stg_2345.txt having a content 1~2~3 4~5~6 another file... (3 Replies)
Discussion started by: angel12345
3 Replies

9. Shell Programming and Scripting

Shell script to populate an array from a csv file

Hi Guys, I've got a script that runs and collects statistics from one of our machines and outputs the data into a csv file. Now, that script runs fine and I managed to create another one (with a lot of help from this forum!!) to trim the csv file down to all the data that I need, rather than all... (9 Replies)
Discussion started by: jimbob01
9 Replies

10. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies
Paranoid::Log::File(3pm)				User Contributed Perl Documentation				  Paranoid::Log::File(3pm)

NAME
Paranoid::Log::File - File Logging Functions VERSION
$Id: File.pm,v 0.83 2010/04/15 23:23:28 acorliss Exp $ SYNOPSIS
use Paranoid::Log; enableFacility('events', 'file', 'debug', '+', $filename); DESCRIPTION
This module logs messages to the log files, and is safe for use with forked children logging to the same files. Each child will open their own filehandles and use advisory locking for writes. This module should not be used directly, Paranoid::Log should be your exclusive interface for logging. SUBROUTINES
/METHODS NOTE: Given that this module is not intended to be used directly nothing is exported. init log remove dump DEPENDENCIES
o Fcntl o Paranoid::Debug o Paranoid::Filesystem o Paranoid::Input SEE ALSO
o Paranoid::Log BUGS AND LIMITATIONS
This isn't a high performance module when dealing with a high logging rate with high concurrency. This is due to the advisory locking requirement and the seeks to the end of the file with every message. This facility is intended as a kind of lowest-common demoninator for programs that need some kind of logging capability. AUTHOR
Arthur Corliss (corliss@digitalmages.com) LICENSE AND COPYRIGHT
This software is licensed under the same terms as Perl, itself. Please see http://dev.perl.org/licenses/ for more information. (c) 2005, Arthur Corliss (corliss@digitalmages.com) perl v5.14.2 2010-04-15 Paranoid::Log::File(3pm)
All times are GMT -4. The time now is 11:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy