09-23-2010
Search and assign using sed
Hi,
I would like to know how to search for a pattern in a file and assign it to a variable using sed.
For example, my hope.txt
address1=123 street,abc city,xyz
address2=456 street,abc city,xyz
In my script I would like to search for patter "address1" and assign the complete line into a variable "A1". How do I do that?
Thanks,
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi all,
Trying to search a file for one word only, then assign that word to a variable. Not sure if this is a grep or awk (or either) function. Should be a simple operation.
Example:
This file contains the string "COMPLETE".
I would like to pull that word out and assign it to a... (2 Replies)
Discussion started by: dejit
2 Replies
2. Shell Programming and Scripting
Hi,
I'm quite new to scripting and I want to modify following line of an existing script:
MYVAR=`subst |grep 'L:\\\:' | sed -e 's/.*\\\//'`;
What I have to do is to use the content of a variable instead of the constant expression 'L:\\\:' as the grep string to be matched.
Assuming I already... (5 Replies)
Discussion started by: snowbiker99
5 Replies
3. Shell Programming and Scripting
Hi Friends,
REQUIREMENT: Want to delete files from the current directory match with the same in the file test.txt
set -x
i=1
echo "i=$i"
COUNT=`sed -n '$=' test.txt`
echo "Count=$COUNT"
while
do
"## Here is error##"
FILETOREMOVE=`sed -n \'$i,1p\' test.txt`
echo $FILETOREMOVE... (5 Replies)
Discussion started by: sourabhsharma
5 Replies
4. UNIX for Dummies Questions & Answers
I'm not sure if the problem I'm seeing is an artifact of sed or simply a beginner's mistake. Here's the problem: I want to add a zero-width space following each underscore between XML tags. For example, if I had the following xml:
<MY_BIG_TAG>This_is_a_test</MY_BIG_TAG>
It should look like... (8 Replies)
Discussion started by: rhetoric101
8 Replies
5. Shell Programming and Scripting
guys,
I need to know how to assing pattern matched string as an input command variable. Here it goes'
My script is something like this.
./routing.sh <Server> <enable|disable>
## This Script takes an input <Server> variable from this line of the script ##
echo $1 | egrep... (1 Reply)
Discussion started by: raghunsi
1 Replies
6. Shell Programming and Scripting
I am a newbie and would like some help with the following -
Trying to search fileA for a string similar to -
AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3
I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies
7. Shell Programming and Scripting
Hi all,
I have a big file (n.txt) with following pattern:
ATOM 1 N SER A 1 122.392 152.261 138.190 1.00 0.00 N
ATOM 2 CA SER A 1 122.726 151.241 139.183 1.00 0.00 C
TER
ENDMDL
ATOM 1 N SER A 1 114.207 142.287 135.439 1.00 0.00 ... (3 Replies)
Discussion started by: bioinfo
3 Replies
8. Shell Programming and Scripting
Hi, I have the following command that parses an xml file to read a node <port>'s value. Hoever the output comes with spaces.
My requirement is to trim the spaces around the value and assign to a variable.
sed -n 's|<port>\(.*\)</port>|\1|p' ../cfg.xml
How do I go about it? (6 Replies)
Discussion started by: sai2013
6 Replies
9. Shell Programming and Scripting
(5 Replies)
Discussion started by: radioactive9
5 Replies
10. UNIX for Beginners Questions & Answers
Hello,
I know how to use sed for simple search but i need to search something like below in a file.
From the below string, i need to find and replace only ./ with a $ using sed.
./abcd/str.xyz
Thanks in advance
KK (8 Replies)
Discussion started by: Pavan Kumar19
8 Replies
LEARN ABOUT DEBIAN
text::vcard::node
Text::vCard::Node(3pm) User Contributed Perl Documentation Text::vCard::Node(3pm)
NAME
Text::vCard::Node - Object for each node (line) of a vCard
SYNOPSIS
use Text::vCard::Node;
my %data = (
'param' => {
'HOME,PREF' => 'undef',
},
'value' => ';;First work address - street;Work city;London;Work PostCode;CountryName',
);
my $node = Text::vCard::Node->new({
node_type => 'address', # Auto upper cased
fields => ['po_box','extended','street','city','region','post_code','country'],
data => \%data,
});
DESCRIPTION
Package used by Text::vCard so that each element: ADR, N, TEL etc are objects.
You should not need to use this module directly, Text::vCard does it all for you.
METHODS
new()
my $node = Text::vCard::Node->new({
node_type => 'address', # Auto upper cased
fields => ['po_box','extended','street','city','region','post_code','country'],
data => \%data,
});
value()
# Get the value for a standard single value node
my $value = $node->value();
# Or set the value
$node->value('New value');
other()'s
# The fields supplied in the conf area also methods.
my $po_box = $node->po_box(); # if the node was an ADR.
# Set the value.
my $street = $node->street('73 Sesame Street');
unit()
my @units = @{$org_node->unit()};
$org_node->unit(['Division','Department','Sub-department']);
As ORG allows unlimited numbers of 'units' as well as and organisation 'name', this method is a specific case for accessing those values,
they are always returned as an array reference, and should always be set as an array reference.
types()
my @types = $node->types();
or
my $types = $node->types();
This method will return an array or an array ref depending on the calling context of types associated with the $node, undef is returned if
there are no types.
All types returned are lower case.
is_type()
if($node->is_type($type) {
# ...
}
Given a type (see types() for a list of those set) this method returns 1 if the $node is of that type or undef if it is not.
is_pref();
if($node->is_pref()) {
print "Prefered node"
}
This method is the same as is_type (which can take a value of 'pref') but it specific to if it is the prefered node. This method is used to
sort when returning lists of nodes.
add_types()
$address->add_types('home');
my @types = qw(home work);
$address->add_types(@types);
Add a type to an address, it can take a scalar or an array ref.
remove_types()
$address->remove_types('home');
my @types = qw(home work);
$address->remove_types(@types);
This method removes a type from an address, it can take a scalar or an array ref.
undef is returned when in scalar context and the type does not match, or when in array ref context and none of the types match, true is
returned otherwise.
group()
my $group = $node->group();
If called without any arguments, this method returns the group name if a node belongs to a group. Otherwise undef is returned.
If an argument is supplied then this is set as the group name.
All group names are always lowercased.
For example, Apple Address book used 'itemN' to group it's custom X-AB... nodes with a TEL or ADR node.
export_data()
my $value = $node->export_data();
This method returns the value string of a node. It is only needs to be called when exporting the information back out to ensure that it
has not been altered.
NOTES
If a node has a param of 'quoted-printable' then the value is escaped (basically converting Hex return into
as far as I can see).
EXPORT
None by default.
AUTHOR
Leo Lapworth, LLAP@cuckoo.org
SEE ALSO
Text::vCard Text::vCard::Addressbook
perl v5.10.1 2010-08-19 Text::vCard::Node(3pm)