Sponsored Content
Top Forums UNIX for Advanced & Expert Users Pulling out fields from a file Post 7704 by eddie on Sunday 30th of September 2001 03:31:23 PM
Old 09-30-2001
Another method, 3 commands, a little bit longer, but easier to understand. Here I assume there are 5 fields in the source file,

(awk -F "," '{print FNR, $1}' filename ; awk -F "," '{print FNR, $2}' filename ; awk -F "," '{print FNR, $3}' filename ; awk -F "," '{print FNR, $4}' filename ; awk -F "," '{print FNR, $5}' filename) | grep "NAME=" | sort > tab1

(awk -F "," '{print FNR, $1}' filename ; awk -F "," '{print FNR, $2}' filename ; awk -F "," '{print FNR, $3}' filename ; awk -F "," '{print FNR, $4}' filename ; awk -F "," '{print FNR, $5}' filename) | grep "POSTCODE=" | sort > tab2

join tab1 tab2

"awk" outputs the fields with line number (record number), then we "join" them together by line numebr. Just like we make a query / joint between 2 tables, "select tab1.NAME, tab2.POSTCODE from tab1, tab2 where tab1.linenumber=tab2.linenumber"
Smilie

Last edited by eddie; 09-30-2001 at 05:22 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

pulling the following line from a file

I have return files from a process that has then original input record followed on the next line by a response record..either AA,........... for accepted or EE,.......... for errored. i.e 11,new,123 AA,accepted 12,exist,443 EE,rejected 13,old,223 AA,accepted I want to write a small... (4 Replies)
Discussion started by: peter.herlihy
4 Replies

2. Shell Programming and Scripting

pulling a column from a file in ksh

I would like to pull a column from a file and place it in a variable: The file would look like this: N.Korea gibberish garbage S.Korea gibberish garbage USA gibberish garbage Iraq gibberish garbage Canada gibberish garbage and items in the first... (8 Replies)
Discussion started by: dangral
8 Replies

3. Shell Programming and Scripting

Pulling data and following lines from file

I saw a few posts close to what i want to do, but they didn't look like they would work exactly.. or I need to think out of the box on this. I have a file that I keep server stats in for my own performance analysis. this file has the output from many commands in it (uptime, vmstats, ps, swap... (2 Replies)
Discussion started by: MizzGail
2 Replies

4. UNIX for Dummies Questions & Answers

Pulling a file off a backup tape

I have AIX 5.1 This may sound like a really dumb question but I have never done this before. I would like to pull a file off a backup tape and put back on the AIX is this as simple as as doing a mount /dev/rmt1 then the file name that is on the tape /dump/rpt/xxxxxx Do I just copy it... (14 Replies)
Discussion started by: rocker40
14 Replies

5. Shell Programming and Scripting

Script for pulling words of 4 to 7 characters from a file

Even just advice on where to start would be helpful. Thank You (2 Replies)
Discussion started by: Azeus
2 Replies

6. Shell Programming and Scripting

Pulling Ip's from log and redirecting to a file

Hi all, I am fairly new to scripting, but I do try and script as much as possible but the more advanced stuff does tend to boggle my mind a bit. I am at a bit of a loss with this one. I get entries in my DNS logs, like the below: I want to extract only the IP address, without the hashes... (5 Replies)
Discussion started by: codenjanod
5 Replies

7. Shell Programming and Scripting

pulling different fields from a csv file

Hi, I have a requirment where I need to pull different columns from a .csv file. Here is the sample of the csv file. account,item,flag1,flag2,flag3,flag4,flag5,......feed,tran I will be have a config.txt file which will have the following information. item,flag5,flag10,feed,tran... (2 Replies)
Discussion started by: akdevula
2 Replies

8. UNIX for Dummies Questions & Answers

Pulling Parms from Config File

Hello all, I'm working on a general script for something at work. I'm an up-and-comer backup for a Shell Scripter this company has had for 35 years lol. Anyway, I have a config file I'm trying to pull Variables from as the Config File is used for multiple scripts. Does the below make sense and... (7 Replies)
Discussion started by: phunk
7 Replies

9. Shell Programming and Scripting

Pulling Data, Then Moving to the Next File

I'm scanning a list of emails- I need to pull 2 pieces of data, then move to the next file: Sender's Email Address Email Date I need these to be outputted into a single column- separated by a ",". Like this: Email1's Address, Email1's Date Stamp Email2's Address, Email2's Date Stamp... (4 Replies)
Discussion started by: sudo
4 Replies

10. Shell Programming and Scripting

Partial file pulling

I am connecting to another server through sftp. I am running one batch script to pull file from another server. sometimes i am receiving partial files. I am using below commands in batch script. ls -ltr new.txt mget new.txt bye The file is of 1 MB only.In most of the cases , i received... (6 Replies)
Discussion started by: srinath01
6 Replies
EXPAND(1)						    BSD General Commands Manual 						 EXPAND(1)

NAME
expand, unexpand -- expand tabs to spaces, and vice versa SYNOPSIS
expand [-t tab1,tab2,...,tabn] [file ...] unexpand [-a | -t tab1,tab2,...,tabn] [file ...] DESCRIPTION
The expand utility processes the named files or the standard input writing the standard output with tabs changed into blanks. Backspace characters are preserved into the output and decrement the column count for tab calculations. The expand utility is useful for pre-process- ing character files (before sorting, looking at specific columns, etc.) that contain tabs. The unexpand utility puts tabs back into the data from the standard input or the named files and writes the result on the standard output. The following options are available: -a (unexpand only.) By default, only leading blanks and tabs are reconverted to maximal strings of tabs. If the -a option is given, then tabs are inserted whenever they would compress the resultant file by replacing two or more characters. -t tab1,tab2,...,tabn Set tab stops at column positions tab1, tab2, ..., tabn. If only a single number is given, tab stops are set that number of column positions apart instead of the default number of 8. ENVIRONMENT
The LANG, LC_ALL and LC_CTYPE environment variables affect the execution of expand and unexpand as described in environ(7). EXIT STATUS
The expand and unexpand utilities exit 0 on success, and >0 if an error occurs. STANDARDS
The expand and unexpand utilities conform to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
The expand command appeared in 3.0BSD. BSD
October 13, 2006 BSD
All times are GMT -4. The time now is 02:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy