Sponsored Content
Top Forums Shell Programming and Scripting ...yet another string of awk/sed questions from a RegExp-Challenged luser %-\ Post 302358500 by cfajohnson on Friday 2nd of October 2009 06:37:04 PM
Old 10-02-2009
Quote:
Originally Posted by Scrutinizer
Nice puzzle, Steve. This works in ksh. Do you have that on your system?

If you use [ -n "$var" ] instead of [[ $var != "" ]], the script will work in any shell.
Quote:

Code:
#!/bin/ksh
{ sed '/masks/ s/^/\n/'  infile | sed 's/^\([CDS]\) \(.*\)$/\2 \1/' |\


Why two calls to sed?

Code:
sed -e '/masks/ s/^/\n/' -e 's/^\([CDS]\) \(.*\)$/\2 \1/' infile

Quote:

The sort statement is very implementation dependent. This syntax is for GNU sort.

That is POSIX sort which most systems now have; that means your sort code will work almost everywhere.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

regexp with sed again!!!

please help: I want to add 1 space between string and numbers: input file: abcd12345 output file: abcd 1234 The following sed command does not work: sed 's/\(+\)\(+\)/\1 \2/' file Any ideas, please Andy (2 Replies)
Discussion started by: andy2000
2 Replies

2. Shell Programming and Scripting

regexp to get first line of string

Hi everybody for file in * #Bash performs filename expansion #+ on expressions that globbing recognizes. do output="`grep -n "$1" "$file"`" echo "$file: `expr "$output" : '\(^.*$\)'`" done In the above bash script segment, I try to print just the first line of string named... (3 Replies)
Discussion started by: jonas.gabriel
3 Replies

3. Shell Programming and Scripting

sed regexp

Hi, I am not that good with reg exp and sed. But I was just looking at something the other day and came across a situation. When I ran the below command: echo "123 word" | sed 's/*/(&)/' the op was: (123) word But when I ran: echo "123 word" | sed 's/*/(&)/g' the o/p was: (123)... (4 Replies)
Discussion started by: King Nothing
4 Replies

4. UNIX for Dummies Questions & Answers

sed before and after regexp

Dear all i have the code which print 1 line of context before and after regexp, with line number sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h the code work well but any one can tell me what each letter mean {=;x;1!p;g;$!N;p;D;} also how i can print 2 line before and onle line after ... (2 Replies)
Discussion started by: soly
2 Replies

5. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

Hello all According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values example, running this script/command like ./script.sh xxapp I would expect as output: 102 116 112 ./script.sh xxapp2... (2 Replies)
Discussion started by: cabrao
2 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. Shell Programming and Scripting

Couple of easy questions for experts on awk/sed

Hello Experts.. I have 3-4 C codes with Oracle SQL statements embedded. All the SQL statements starts with EXEC SQL keyword and ends with ;. I want to extract all the SQL statements out of these codes. I did awk '/^EXEC SQL/,/\;/' inputFile (I use this on all of the codes individually). That... (2 Replies)
Discussion started by: juzz4fun
2 Replies

8. Shell Programming and Scripting

Regexp for string that might contain a given character

I'm probably just not thinking of the correct term to search for :-) But I want to match a pattern that might be 'ABC' or '1ABC' there might be three characters, or there might be four, but if there are four, the first has to be 1 (1 Reply)
Discussion started by: jnojr
1 Replies

9. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

10. UNIX for Beginners Questions & Answers

awk or sed to print the character from the previous line after the regexp match

Hi All, I need to print the characters in the previous line just before the regular expression match Please have a look at the input file as attached I need to match the regular expression ^ with the character of the previous like and also the pin numbers and the output file should be like... (6 Replies)
Discussion started by: kshitij
6 Replies
CTLUSER(8)						      System Manager's Manual							CTLUSER(8)

NAME
ctluser - control lusers SYNOPSIS
ctluser [ -h ] [ -m ] command [ argument... ] DESCRIPTION
Ctluser sends a message to the control channel of a given luser(8) This command can only be run by the sysadmin(1) In the normal mode of behavior, the message is sent to the luser's brain, which then performs the requested action and sends back a reply with a text message and the exit code for ctluser. If the luser's brain successfully performed the command, ctluser will exit with a sta- tus of zero and print the reply on standard output. The ``-m'' flag is used to display an MPEG of the results of the given command on the console of the sysadmin(1) Note that this requires the sysadmin(1) to be running an X server. To see a command summary, use the ``-h'' flag. If a command is included when ctluser is invoked with the ``-h'' flag, then only the usage for that command will be given. The complete list of commands follows. Note that all commands have a fixed number of arguments. If a parameter can be an empty string, then it is necessary to specify it as two adjacent quotes, like "". addhist <entry> Add an entry to the luser's employment record. allow reason Allow a luser to use the computer system again. The reason must be the same text given with an earlier ``reject'' command. Note that this command is currently not implemented. begin name Begin a new luser(1) with the given file. Note that this command is currently not implemented. cancel pid Causes a process of a luser to be killed changegroup group Changes a luser from their current workgroup to the one specified. checkfile Forces a user to return to a paper based system drop Causes a large mass to drop onto the luser from a great height. flushlogs Destorys all logs of the actions done by the sysadmin(1) to the luser. go reason The luser is fired for the given reason. hangup Makes the luser hang themselves mode Displays the operating mode of the luser newgroup group Causes a luser to make their own newgroup up pause thought Makes the luser pause for the given thought. Note that this may cause some lusers to crash shutdown reason Makes the luser shutdown. This is essentially the same as killing them signal sig Sends the given signal to the luser throttle reason Causes the luser to throttle themselves trace item flag Gives the sysadmin(1) information on what the luser is doing. BUGS
Ctluser sometimes has the effect of lusers complaining the to management. The use of bosskill(8) maybe required at this point. HISTORY
Written by Simon Burr <simes@tcp.co.uk>. Based upon the manual page for ctlinnd(8), part of the InterNetNews system. SEE ALSO
luser(1), sysadmin(1), bosskill(8) 19 October 1995 CTLUSER(8)
All times are GMT -4. The time now is 10:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy