Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Expanding variables with Ed Bash 3.2.33 Post 302339978 by de_la_espada on Saturday 1st of August 2009 10:18:10 AM
Old 08-01-2009
Thanks for taking the trouble to reply.
If anyone can think of any easy way to do what I want to do then let me know.
Curently traawling through the mountain of find and replace postings on the forum.

Simply open file, find Word in line then replace word1 with word2. Then write change to file.
Word is a unique field in file so will only exist on one line. Word1 will only be present once per line.

cheers

Nick

Code:
 sed -i "/$address/s/$pat1/$pat2/" accounts.txt

Where address finds you the line, then pat1 is replaced by pat2. Only occurs once per line.

Last edited by de_la_espada; 08-01-2009 at 12:19 PM.. Reason: Found Solution
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

expanding dotted paths to absolute ones in bash or sh

I have a little script to help me manage a gallery of image files. It makes symbolic links to every file in and below the current directory, placing them in a target directory which is passed to the script as a parameter. Unfortunately, the script pukes when I pass a parameter that contains... (4 Replies)
Discussion started by: TanRanger
4 Replies

2. UNIX for Advanced & Expert Users

Expanding Variables in User Input

If have var='$variable' how can I expand $variable. I have tried many thing like duble quotes/braces etc, but nothing worked. I need the solution ASAP. (2 Replies)
Discussion started by: Bsk
2 Replies

3. Shell Programming and Scripting

Bash variables

Ummm can anybody help me with this one? Its prob quite simple. I bascially have a file name say J1x2x3x7.dat Im using the file name as a variable in a bash script. Want I want to do is extract most of the file name and make it a new variable expect with say one of the number now a... (2 Replies)
Discussion started by: RichieFondel
2 Replies

4. Shell Programming and Scripting

how to use in bash variables and quotes

I have some troubles with variables and quotes... I want: if $URL is empty (no user input) go to http://www.localhost/index.php/ else add this string (search) "?s=+$URL" EXAMPLE: No user input string= http://www.localhost/index.php/ User input = "unix" string=... (3 Replies)
Discussion started by: aspire
3 Replies

5. Shell Programming and Scripting

awk issue expanding variables in ksh script

Hi Guys, I have an issue with awk and variables. I have trawled the internet and forums but can't seem to get the exactt syntax I need. I have tried using awk -v and all sorts of variations but I have hit a brick wall. I have spent a full day on this and am just going round in circles. ... (3 Replies)
Discussion started by: gazza-o
3 Replies

6. Shell Programming and Scripting

BASH arrays and variables of variables in C++

Sometimes it is handy to protect long scripts in C++. The following syntax works fine for simple commands: #define SHELLSCRIPT1 "\ #/bin/bash \n\ echo \"hello\" \n\ " int main () { cout <<system(SHELLSCRIPT1); return 0; } Unfortunately for there are problems for: 1d arrays:... (10 Replies)
Discussion started by: frad
10 Replies

7. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

8. Shell Programming and Scripting

Possible ksh93 Bug Expanding Variables?

My OS is Linux (kernel 4.08.something) and AIX (7100-04-01-1543), the used ksh versions are: ksh88: Version M-11/16/88f (AIX) ksh93: Version M 93t+ 2009-05-01 (AIX), Version M 93u (Linux) When writing a parser for stanza files in ksh i encountered a rather strange behavior. Here is a... (4 Replies)
Discussion started by: bakunin
4 Replies

9. UNIX for Beginners Questions & Answers

Bash argument not expanding in script

I pass an argument to bash as run. The first command in green executes as expected, however the second in blue fails as the $run does not expand. I tried to escape the variable with \ thinking the quotes were making the literal translation and also "${run}" but both did not work to expand the... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. UNIX for Beginners Questions & Answers

[BASH] eval command not expanding variables as expected.

Hi Guys, I wrote a collection of bash functions years ago and now need to use them again but I'm getting some error messages when eval tries to expand the variables names. I recollect that I used the shopt command to set one of the options but I can't quite remember the command that I... (8 Replies)
Discussion started by: ASGR
8 Replies
alex(1) 						      General Commands Manual							   alex(1)

NAME
alex - extract addresses from message headers (only available within the message handling system, mh) SYNOPSIS
alex [+folder] [msgs] [options] OPTIONS
Accepts an address that you type in, rather than taking an address from a message. If any -field option is specified, it is ignored. Spec- ifies the name of the alias file, in which aliases are placed. You must provide a file name or a dash (-) as an argument with this option. There is no default value. If the value given for this option is -, or the option is not specified, alex will print the output to your screen. If you do not give the full pathname of your alias file, alex will look for the alias file in your Mail directory, as specified in the Path field of your file. If alex cannot locate the alias file in the directory that you specify, it will ask you whether or not you wish to create one. You can set up an alias file to be used by alex in your mh_profile(4) for more information. Like other mail commands, alex uses the Aliasfile entry to find the alias file. Prevents any repetition of the same address in the output of an alex command. You can use this option when there are multiple occurrences of an address in an address group and you want just one occurrence of it in your alias. The default is -nocompress. Specifies the name of a header field. The name of the field is not case-sensitive. If you spec- ify this option without providing an argument, the default values are: -field reply-to/sender/from/to. You can set up your own default values for the -field option in your mh_profile(4). Examples of field names are From, cc and To. You must not type a colon after the name of a field. When more field names follow, in the form /name, the message header is searched for each of the fields in turn until one is found. Only the first header field found to contain an address is used; the rest are ignored. The option -nofield excludes the named field. The special name, all, means all fields, and can be used as a value for the -nofield option to override any default order of header fields, otherwise -field values are appended to any default values. Specifies that any address replacements or appendings will apply to all occurrences of that alias name. Normally, if an alias name is entered in the alias file more than once, any actions performed by alex are performed only on the first occurrence of that alias name. The -global option ensures that any changes are made to all occurrences of the alias. Whenever this option is specified, a message is broadcast to your screen telling you how many entries in the alias file have been changed. Prints a list of the valid options for this command. Specifies the alias name for address information extracted. The alex command appends a colon (:) to the name as required by mh-alias(4). If you do not specify this option,alex will print extracted addresses to your screen. If you specify this option, you must provide an argument; there is no default value. Extracts addresses interactively. Before adding each address of a list of extracted addresses to an alias group, the mail system will ask you whether you wish the address to be added. The query prompt is written on the standard error output. The default is -noquery. Replaces existing alias with the new list of addresses. By default, if there is an existing alias with the same name as the one you are trying to create, alex appends the new address list to the old alias. If an address appears in both address groups, it is still appended, so that it appears twice in the new alias. You can specify this explicitly by using the -nore- place option. If you specify the -replace option, the new list of addresses replaces the existing group. The default is -noreplace. Specifies the maximum width of your alias file line. If an alias group extends beyond this length, it is continued on the next line, with a backslash () at end of the first line. Any X.400 addresses which are longer than the maximum line length specified by this option are automatically wrapped onto the next line. This option affects the format of each individual entry when it is implemented; any subsequent or previous entries in the alias file remain the same. The default is 72 characters. DESCRIPTION
The address line extraction utility alex extracts electronic mail addresses from message headers and prints the addresses on your screen or places them, with a specified alias name, in an alias file. By default, alex searches for addresses in the current message in the current folder. You can list the messages you wish alex to search giving a msgs argument. You can also search messages in a different folder by giving a +folder argument. You define the fields from which you want addresses by using combinations of field names with the -field option. You can also supply an address yourself as a value to the -address option. Results are printed either to your screen or to a file in mh-alias(4) format. Where there is an address group in the alias file with an alias name identical to one you have specified in an alex command, it may be replaced or the new addresses appended. A copy of the original alias file is kept. By default, alex searches the Reply-to:, Sender:, From: and To: header fields in that order until an address is found. You can set up your own default values for alex in your file; see mh_profile(4). When giving options to the alex command, generally the shortest unique abbreviation suffices. RESTRICTIONS
Because the -nofield option can take the value all as an argument, alex will not recognize a header field called All. If you wish to use such a header field, you should call it X-all. If a command line contains contradictory arguments then the last value specified is used. For example, in the following command, alex only uses the options -name fred and -noreplace: % alex -name sam -name fred -replace -noreplace EXAMPLES
This example takes the address from the From field of the current message, and places it in your alias file with the alias name bob: % alex -field from -alias aliases -name bob The following example shows what happens if you specify an alias file that does not exist. You are asked whether you want to create the file; enter y to create it: % alex -field from -name bob -alias aliases Create alias file "HOME/Mail/aliases"? y The next example takes addresses from two fields, From and cc, and saves them as the alias sales_team: % alex -field from -field cc -alias aliases -name sales_team FILES
Your user profile. SEE ALSO
ali(1), mh(1), pick(1), mh-alias(4), mh_profile(4) alex(1)
All times are GMT -4. The time now is 04:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy