Sponsored Content
Top Forums Shell Programming and Scripting Search flat file and return 3 fields Post 302259715 by da2357 on Tuesday 18th of November 2008 09:04:50 PM
Old 11-18-2008
Quote:
Originally Posted by in2nix4life
Using awk like this may help point you in the right direction:

serialnum=`awk -F"," '/W394830PR/{print $1}' file`
account=`awk -F"," '/W394830PR/{print $2}' file`
ipaddress=`awk -F"," '/W394830PR/{print $3}' file`
Great (and thanks), this got me 99% there. Here's a snippet of what I have, using your idea:

Code:
#!/bin/bash
USERLIST="/Users/johndoe/.bin/xBackup_users"
SRCHFOR="W8735UL8Z5V"
#
USERNAME=`awk -F "," '/W8735UL8Z5V/{print $2}' $USERLIST`
PASSWORD=`awk -F "," '/W8735UL8Z5V/{print $3}' $USERLIST`
RSYNCIP=`awk -F "," '/W8735UL8Z5V/{print $4}' $USERLIST`
#
clear
echo
echo Your account name is $USERNAME
echo Your password is $PASSWORD
echo Your IP address is $RSYNCIP
echo
exit

To finish this, I'd rather use the variable SRCHFOR in the awk command and I've tried it several ways, but aren't sure how to get it to work. (I already separate code that extracts the serial number from the machine.)

Any final ideas?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to return all the ID's from file based on the distribution ID search

Hi, Please help me out on this I have to store some distribution lists(dl) in a file say mail.txt Say the file format be d1 = alok@yahoo.co.in;alvin@rediffmail.com;vijay@yahoo.com; & so on... d2 = abhinav@gmail.com;dalpit@hotmail.com;garima@yahoo.com;& so on... d3 = .... & so on Now what... (1 Reply)
Discussion started by: kumbhatalok
1 Replies

2. UNIX for Dummies Questions & Answers

Search for String within File and Return File Name

How do I search for a string within a file and return the names of the file that contain the string? I would like to search directories and sub-directories. (4 Replies)
Discussion started by: bggibson
4 Replies

3. Shell Programming and Scripting

search fields within a file

I need to be able to search multiple fields within a file that contain blank (nothing). Not sure what command to use? thought it would be grep but not sure how to write it The reason is i have a script that when it does this and identifies a field which has a blank it errors out of the script... (4 Replies)
Discussion started by: Pablo_beezo
4 Replies

4. Shell Programming and Scripting

`find`, pulling 1st field from ASCII flat file as search/-name?

Hey Everyone! I have searched around for this on Unix.com and Google, and I'm either not phrasing my search properly or this is not as simple as I thought... I have a script that runs on a nightly basis that pulls one field worth of data from an internal MySQL database and populates to an... (2 Replies)
Discussion started by: Gecko12332
2 Replies

5. UNIX for Dummies Questions & Answers

Search flat file in specific byte

I am on AIX Unix. I want to read a flat file for a string in a certain byte. I want to find the value: 943034 in column 56; and write out just those records to another file. Also, could I get the line/record number of where it was found in the input file? Thank you, sboxtops (1 Reply)
Discussion started by: sboxtops
1 Replies

6. UNIX for Dummies Questions & Answers

Search specific pattern in file and return number of occurence

Hi I want to search for a specific pattern in file Say ABC;HELLO_UNIX_WORLD;PQR ABC;HELLO_UNIX_WORLD_IS_NOT_ENOUGH;XYZ ABC;HELLO_UNIX_FORUM;LMN Pattern to search is : "HELLO_UNIX_*****" and not "HELLO_UNIX_***_***_" I mean after "HELLO_UNIX" there can only be one word.In this case... (2 Replies)
Discussion started by: dashing201
2 Replies

7. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

8. Shell Programming and Scripting

gawk script to search and replace text in a flat file

Hi I am new to unix and newbie to this forum. I need help in writing a gawk script that search and replace particular text in a flat file. Input file text : ZIDE_CONTROL000 100000000003869920900000300000001ISYNC 000002225489 0000000002232122 20120321 16:40:53 ZIDE_RECORD000... (5 Replies)
Discussion started by: gkausmel
5 Replies

9. Shell Programming and Scripting

awk to delete fields from flat file

I would like to know awk command to delete the specific feild from a flat file delimited by '|' if the first feild starts with 354 I tried awk 'BEGIN {FS=OFS="|"} {$16=""; sub(/\|/, "")}'1 Input file: 354|||||GROUND||97||JUDD STREET|||LONDON||WC1H 9JG|ADI001| 354|||||FLAT 1... (10 Replies)
Discussion started by: Aditya_001
10 Replies

10. Shell Programming and Scripting

How to search for blank fields in a text file from a certain position?

Sample txt file : OK00001111112| OK00003443434|skjdaskldj OK32812983918|asidisoado OK00000000001| ZM02910291029|sldkjaslkjdasldjk what would be the shell script to figure out the blank space (if any) after the pipe sign? (4 Replies)
Discussion started by: chatwithsaurav
4 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 09:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy