This works for me assuming that searchName == John, $2 == Wall. If you've invoked your script with just John on the command line, $2 will be null, then you'll end up with the results that you posted. The small script I wrote to test your code includes some error checking that might be beneficial in your case so I've posted it as an example.
I would recommend assigning $2 to a named variable; while it is fine the way it is, it makes your script easier to read if it were something like this:
I also don't believe that you need to escape the spaces. This should work:
and again makes the code easier to read.
---------- Post updated at 13:13 ---------- Previous update was at 13:10 ----------
Thought I would also note that I dropped the -i from my testing because the version of sed that I prefer does not implement it. It should work just fine if you prefer to use that option.
Hi Guys,
I have a file like this:
aaa b c d e f
fsss g h i k l
qqq r t h n
I want:
aaa b c d e f
fsss g h i k l
qqq r t h , n
ggg p t e d u
qqq i o s , k (2 Replies)
Hi,
I know there are lots of threads on replacing text within files, usually using sed or awk. However, I find it hard to adapt examples that I found to my specific case. I am kind of new to UNIX and have hard times learning the syntax either for sed or awk so I would appreciate any help. Here's... (5 Replies)
Dear UNIX community,
I would like to to count characters from a specific row and have them displayed line-by-line.
I have a file called testAwk2.csv which contain the following data:
rabbit penguin goat
giraffe emu ostrich I would like to count in the middle row individually... (4 Replies)
I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work.
Brief overview:
I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
I have a text file like this:
subject1:LecturerA:10
subject2:LecturerA:40
if I was given string in column 1 and 2 (which are subject 1 and LecturerA) , i need to update 3rd field of that line containing that given string , which is, number 10 need to be updated to 100 ,for example.
The... (6 Replies)
Hi...friends....
I want to create inventory...information for that I need to read some specific row say 2nd row from 1st 3 column and and write data with particular file used, I have some more column also but I need only 3 column data of first entry after header
I attached sample file..those... (12 Replies)
Hi,
I have a ldif file like below:
version: 1
dn: cn=Test Group,ou=Applications,dc=xyz,dc=com
objectClass: groupOfUniqueNames
objectClass: top
cn: Test Group
uniqueMember: uid=abc,ou=People,o=xyz,o=Corporate,dc=xyz,dc=com
dn: cn=Test Sub Group,cn=Test... (4 Replies)
Hello,
i need help with awk.
I have this file:
cat number
DirB port 67 er_enc_out 0 er_bad_os 0
DirB port 71 er_enc_out 56 er_bad_os 0
DirB port 74 er_enc_out 0 er_bad_os 0
DirB port 75 ... (4 Replies)
I am trying to add a condition to the below perl that will capture the GTtag and place a specific string in the last field of each line. The problem is that the GT value used is not right after the tag rather it is a few fields away. The values should always be 0/1 or 1/2 and are in bold in the... (12 Replies)
In the below I am trying to use awk to match all the $13 values in input, which is tab-delimited,
that are in $1 of gene which is just a single column of text.
However only the line with the greatest $9 value in input needs to be printed.
So in the example below all the MECP2 and LTBP1... (0 Replies)
Discussion started by: cmccabe
0 Replies
LEARN ABOUT OSF1
read
read(1) General Commands Manual read(1)NAME
read - Reads a line from standard input
SYNOPSIS
read [-r] var...
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
read: XCU5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
OPTIONS
Do not treat a backslash character in any special way. Consider each backslash to be part of the input line.
Note
The -r option is included to enable read to subsume the purpose of the obsolete line utility.
OPERANDS
The name of an existing or non-existing shell variable.
DESCRIPTION
The read utility reads a single line from standard input.
By default, unless the -r option is specified, backslash () acts as an escape character. If standard input is a terminal device and the
invoking shell is interactive, read prompts for a continuation line in the following cases: The shell reads an input line ending with a
backslash, unless the -r option is specified. A here-document is not terminated after a newline character is entered.
The line is split into fields as in the shell (see the sh(1) reference page); the first field is assigned to the first variable var, the
second field to the second variable var, and so forth. If there are fewer var parameters specified than there are fields, the leftover
fields and their intervening separators are assigned to the last var. If there are fewer fields than vars, the remaining vars are set to
empty strings.
The setting of variables specified by the var parameters affects the current shell execution environment. If read is called in a subshell
or separate utility execution environment, such as one of the following, it does not affect the shell variables in the caller's environ-
ment:
(read foo) nohup read ... find . -exec read ... ;
NOTES
The -r option is included to enable read to subsume the purpose of the obsolete line utility.
RESTRICTIONS
The results are undefined if an end-of-file is detected following a backslash at the end of a line when -r is not specified.
EXIT STATUS
The following exit values are returned: Successful completion. End-of-file was detected or an error occurred.
EXAMPLES
The following command prints a file with the first field of each line moved to the end of the line:
while read -r xx yy do
printf "%s %s
" "$yy" "$xx" done < input_file
ENVIRONMENT VARIABLES
The following environment variables affect the execution of read: Determines the internal field separators used to delimit fields. Pro-
vides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value
from the default locale is used. If any of the internationalization variables contain an invalid setting, the utility behaves as if none
of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization vari-
ables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed
to multibyte characters in arguments). Determines the locale used to affect the format and contents of diagnostic messages written to
standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. Provides the prompt string that an
interactive shell will write to standard error when a line ending with a backslash is read and the -r option was not specified, or if a
here-document is not terminated after a newline character is entered.
SEE ALSO
Commands: line(1)
Functions: fread(3)
Standards: standards(5)read(1)