05-01-2009
grep command to retrieve one file
The Sed/Grep command is really confusing me. I know I'm missing something that should be really easy to fix. My program displays multiple names after I ask it to display only one, How do I get it to do only one??
it looks like this:
Please enter a name to display?
>> John
(A list then appears)
1. John Doe
2. John Smith
3. John James
Please enter the record that you would like to display on separate page?
>> 3
And then John James should appear on a separate page like this
3.
John James
1234 Main Street
City, State, Zipcode
Telephone Number
However, my program displays every John
_________
my code looks like this:
echo "Please enter a name to display \c"
read name
#Displays all of the names with their record number
grep -in $name phonebook
#Enter the record number to display on separate page
echo "Enter the record number of the name you want to display \c"
read number
record=`grep -i $number phonebook` (I'm Pretty sure this is the error)
clear
grep -in "$name" phonebook | sed -n -e 's/^/\
/' -e 's/:/\
/gp'
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
For examples, I have typed 4 commands in the command prompt:
ls -la
rm -rf /home/user1
du -k /home
find . -name "abc.out" -print
And now I want to retrieve the command which begin with letter "r" (i.e. rm -rf /home/user1), what can I do? (5 Replies)
Discussion started by: laum
5 Replies
2. UNIX for Dummies Questions & Answers
I am trying to search for a pattern in a file containing xml - When I match the search I want to retrieve all the text within the xml brackets..
Whats the best way to read in data between xml tags in a shell script?
ie..
xml returned which I have in a file now is something like below:... (2 Replies)
Discussion started by: frustrated1
2 Replies
3. Shell Programming and Scripting
when I do a df -k for a particular mount i get the result like this
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/ 4128448 3527496 391240 91% /
I need to extract the value 91 from this and use it in my script in an if condition. How will i do it Please advice. (8 Replies)
Discussion started by: codeman007
8 Replies
4. UNIX for Dummies Questions & Answers
Hi,
I'm looking for a command to retrieve a block of lines using sed or grep, probably awk if that can do the job.
In below example,
By searching for words "Third line2" i'm expecting to retrieve the full block starting with 'BEGIN' and ending with 'END' of the search.
Example:
... (3 Replies)
Discussion started by: learning_linux
3 Replies
5. Shell Programming and Scripting
Hi,
I have to store all the command line arguments into an array.
I have the following code.
**********************
#! /bin/sh
set -A arr_no_updates
i=1
while
do
arr_no_updates=$($i)
echo ${arr_no_updates}
i=$(($i+1))
done**************** (1 Reply)
Discussion started by: little_wonder
1 Replies
6. Shell Programming and Scripting
HI All,
I have a log file where the logs will be in the format as given below:
2011-05-25 02:32:51 INFO PROCESS STARTING
2011-05-25 02:32:52 INFO PROCESS STARTED
.
.
.
I want to retrieve only the logs which are less than 5 mins older than current time using grep... (3 Replies)
Discussion started by: rvhg16
3 Replies
7. UNIX for Beginners Questions & Answers
Hi Everyone,
I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file? Please let me know what is the awk command for this?
Regards
Rakesh (1 Reply)
Discussion started by: rakeshp
1 Replies
8. Homework & Coursework Questions
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file?... (6 Replies)
Discussion started by: rakeshp
6 Replies
9. UNIX for Beginners Questions & Answers
I have requirement to search for a text in the file and retrieve required lines that is user defined with unix command.
Eg:
Find the text UNIX in the below file and need to return Test 8 & Test 9
Test 1
Test 2
Test 3
Test 4
UNIX
Test 5
Test 6
Test 7
Test 8
Test 9
Result can... (8 Replies)
Discussion started by: Arunkumarsak4
8 Replies
10. UNIX for Beginners Questions & Answers
I am having trouble matching *two* strings from one file anywhere in a line of a second file, and could use some help getting this figured out. My preference would be to use grep for this because I would like to take advantage of its -A option. The latter is due to the fact that I would like both... (2 Replies)
Discussion started by: jvoot
2 Replies
LEARN ABOUT PHP
array_column
ARRAY_COLUMN(3) 1 ARRAY_COLUMN(3)
array_column - Return the values from a single column in the input array
SYNOPSIS
array array_column (array $array, mixed $column_key, [mixed $index_key = null])
DESCRIPTION
array_column(3) returns the values from a single column of the $array, identified by the $column_key. Optionally, you may provide an
$index_key to index the values in the returned array by the values from the $index_key column in the input array.
PARAMETERS
o $array
- A multi-dimensional array (record set) from which to pull a column of values.
o $column_key
- The column of values to return. This value may be the integer key of the column you wish to retrieve, or it may be the string
key name for an associative array. It may also be NULL to return complete arrays (useful together with $index_key to reindex the
array).
o $index_key
- The column to use as the index/keys for the returned array. This value may be the integer key of the column, or it may be the
string key name.
RETURN VALUES
Returns an array of values representing a single column from the input array.
EXAMPLES
Example #1
Get column of first names from recordset
<?php
// Array representing a possible record set returned from a database
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);
$first_names = array_column($records, 'first_name');
print_r($first_names);
?>
The above example will output:
Array
(
[0] => John
[1] => Sally
[2] => Jane
[3] => Peter
)
Example #2
Get column of last names from recordset, indexed by the "id" column
<?php
// Using the $records array from Example #1
$last_names = array_column($records, 'last_name', 'id');
print_r($last_names);
?>
The above example will output:
Array
(
[2135] => Doe
[3245] => Smith
[5342] => Jones
[5623] => Doe
)
PHP Documentation Group ARRAY_COLUMN(3)