Sponsored Content
Full Discussion: Issue with sed in script
Top Forums Shell Programming and Scripting Issue with sed in script Post 69407 by bthomas on Thursday 14th of April 2005 01:06:00 PM
Old 04-14-2005
Issue with sed in script

I have a loop in a script that is given me an error but, when I do it on the command line it works perfectly. The sed statement has to use the variables from a file so the file is partitioned correctly. I am running on HP:

<Begin error>:
+ cat /u01/bteam/CNAM/1121/.partition
+ read line
+ + echo /^00/p;/^01/p;/^02/p;/^03/p;/^04/p;/^05/p;/^06/p;/^07/p,CWDA
+ cut -d, -f1
part=/^00/p;/^01/p;/^02/p;/^03/p;/^04/p;/^05/p;/^06/p;/^07/p
+ + echo /^00/p;/^01/p;/^02/p;/^03/p;/^04/p;/^05/p;/^06/p;/^07/p,CWDA
+ cut -d, -f2
+ date +%m%d
outfile=/u01/bteam/CNAM/1121/outgoing/CWDA0414
+ sed -n '/^00/p;/^01/p;/^02/p;/^03/p;/^04/p;/^05/p;/^06/p;/^07/p'
+ 0< /u01/bteam/CNAM/1121/lergtemp/LERGT
sed: '/^00/p;/^01/p;/^02/p;/^03/p;/^04/p;/^05/p;/^06/p;/^07/p' is not a recognized function.
+ sort -y
+ tr -d \n\r
+ 1> /u01/bteam/CNAM/1121/outgoing/CWDA0414
+ rm /var/tmp/*
<End Error>

<Begin Code>
cat /u01/bteam/CNAM/1121/.partition | while read line

do

part=`echo $line |cut -d, -f1`

outfile=$opath`echo $line | cut -d, -f2``date +%m%d`

sed -n "'$part'" < $tempfile | sort -y | tr -d "\n\r" > $outfile

rm /var/tmp/*

done
<End Code>

File Contents:
/^00/p;/^01/p;/^02/p;/^03/p;/^04/p;/^05/p;/^06/p;/^07/p,CWDA
/^08/p;/^09/p;/^10/p;/^11/p;/^12/p;/^13/p;/^14/p;/^15/p,CWDB
/^16/p;/^17/p;/^18/p;/^19/p;/^20/p;/^21/p;/^22/p;/^23/p,CWDC
/^24/p;/^25/p;/^26/p;/^27/p;/^28/p;/^29/p;/^30/p;/^31/p;/^32/p,CWDD
/^33/p;/^34/p;/^35/p;/^36/p;/^37/p;/^38/p;/^39/p;/^40/p,CWDE
/^41/p;/^42/p;/^43/p;/^44/p;/^45/p;/^46/p;/^47/p;/^48/p,CWDF
/^49/p;/^50/p;/^51/p;/^52/p;/^53/p;/^54/p;/^55/p;/^56/p,CWDG
/^57/p;/^58/p;/^59/p;/^60/p;/^61/p;/^62/p;/^63/p;/^64/p;/^65/p,CWDH
/^66/p;/^67/p;/^68/p;/^69/p;/^70/p;/^71/p;/^72/p;/^73/p,CWDI
/^74/p;/^75/p;/^76/p;/^77/p;/^78/p;/^79/p;/^80/p;/^81/p,CWDJ
/^82/p;/^83/p;/^84/p;/^85/p;/^86/p;/^87/p;/^88/p;/^89/p;/^90/p,CWDK
/^91/p;/^92/p;/^93/p;/^94/p;/^95/p;/^96/p;/^97/p;/^98/p;/^99/p,CWDL
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

2. Shell Programming and Scripting

Sed Issue....

Can someone help me "port" this to AIX sed? sed '/nas/{n;s/true/false/}' I know it doesn't like the ; but i don't know how else to do it.... never had to sed on an AIX box :D (7 Replies)
Discussion started by: DeviousPete
7 Replies

3. Shell Programming and Scripting

sed issue

Hi All I'm getting this error while executing a sed script sed: 0602-404 Function /</ i\ File from New Cube: cannot be parsed. sed "/</ i\ File from New Cube: />/ i\ File from Old Cube:" difference1.txt > Difference.txt I've a file like this < Y2008 Dec ..... .... ... 345 I want... (6 Replies)
Discussion started by: Celvin VK
6 Replies

4. Shell Programming and Scripting

one more issue last- sed

hi i have following sed command this replaces "** in filename1 with octal value 007 filename2 when i put it in script it wont work but it works from command line my OS is sun OS ---------- Post updated at 06:38 PM ---------- Previous update was at 06:14 PM ---------- i... (10 Replies)
Discussion started by: er_zeeshan05
10 Replies

5. Shell Programming and Scripting

stuck on first script with sed issue

Hi, I'm developing my first bash script and have made good progress but stuck at this point. I've run sed on a text file to extract some data and have saved it into a variable e.g. $blah the variable contains emails as follows e.g. <a@b.com> <b@c.com> I'm now trying to edit... (2 Replies)
Discussion started by: newb1000
2 Replies

6. Shell Programming and Scripting

sed issue

Hi guys. Can somone advise as to what the problem is with the following sed command? 1) read -p "Please enter new username you wish to replace old: " new_username sed "s/$username/$new_username/" information_file ;; This is one of the case statements included but I'm... (1 Reply)
Discussion started by: jjb1989
1 Replies

7. Shell Programming and Scripting

sed issue

I can't get this code to work, could I get some help... sed -i '' "s:${shLogpath1}${cell}:${shLogpath2}${cell}:g" test.txt Any Ideas, I think I need to separate the variables some how? (2 Replies)
Discussion started by: digitalviking
2 Replies

8. Shell Programming and Scripting

sed script to parse logs issue

I have this script to parse some logs: #!/bin/bash id=$1 shift sed "/(id=$id)/,/^$/!d" "$@" Usage: ./script.sh 1234 logfile The logs have an empty line before the logged events/timestamps -- most of the time. And this is my issue, since when there is no empty line, it will catch things... (4 Replies)
Discussion started by: KidCactus
4 Replies

9. Shell Programming and Scripting

sed issue

I'm trying to change a date in a couple of large files using SED. The problem is when I use the -n parameter, it doesn't actually change the file. When I leave out the -n, it sends the whole file to the screen, but it does appear to change it. The problem is, these files are very large and it... (8 Replies)
Discussion started by: Drenhead
8 Replies

10. Shell Programming and Scripting

sed command issue in script

Hi, I am using sed command to extract data from my log file for a certain time interval. From and To "time" are my input arguments. Now if i use the sed command on command line. I get the desired results and If i use it in script.It fails. sed command as command line: sed -n '/04-Mar-2015... (6 Replies)
Discussion started by: oberoi1403
6 Replies
regex(1F)							   FMLI Commands							 regex(1F)

NAME
regex - match patterns against a string SYNOPSIS
regex [-e] [-v "string"] [pattern template] ... pattern [template] DESCRIPTION
The regex command takes a string from the standard input, and a list of pattern / template pairs, and runs regex() to compare the string against each pattern until there is a match. When a match occurs, regex writes the corresponding template to the standard output and returns TRUE. The last (or only) pattern does not need a template. If that is the pattern that matches the string, the function simply returns TRUE. If no match is found, regex returns FALSE. The argument pattern is a regular expression of the form described in regex(). In most cases, pattern should be enclosed in single quotes to turn off special meanings of characters. Note that only the final pattern in the list may lack a template. The argument template may contain the strings $m0 through $m9, which will be expanded to the part of pattern enclosed in ( ... )$0 through ( ... )$9 constructs (see examples below). Note that if you use this feature, you must be sure to enclose template in single quotes so that FMLI does not expand $m0 through $m9 at parse time. This feature gives regex much of the power of cut(1), paste(1), and grep(1), and some of the capabilities of sed(1). If there is no template, the default is $m0$m1$m2$m3$m4$m5$m6$m7$m8$m9. OPTIONS
The following options are supported: -e Evaluates the corresponding template and writes the result to the standard output. -v "string" Uses string instead of the standard input to match against patterns. EXAMPLES
Example 1 Cutting letters out of a string To cut the 4th through 8th letters out of a string (this example will output strin and return TRUE): `regex -v "my string is nice" '^.{3}(.{5})$0' '$m0'` Example 2 Validating input in a form In a form, to validate input to field 5 as an integer: valid=`regex -v "$F5" '^[0-9]+$'` Example 3 Translating an environment variable in a form In a form, to translate an environment variable which contains one of the numbers 1, 2, 3, 4, 5 to the letters a, b, c, d, e: value=`regex -v "$VAR1" 1 a 2 b 3 c 4 d 5 e '.*' 'Error'` Note the use of the pattern '.*' to mean "anything else". Example 4 Using backquoted expressions In the example below, all three lines constitute a single backquoted expression. This expression, by itself, could be put in a menu defini- tion file. Since backquoted expressions are expanded as they are parsed, and output from a backquoted expression (the cat command, in this example) becomes part of the definition file being parsed, this expression would read /etc/passwd and make a dynamic menu of all the login ids on the system. `cat /etc/passwd | regex '^([^:]*)$0.*$' ' name=$m0 action=`message "$m0 is a user"`'` DIAGNOSTICS
If none of the patterns match, regex returns FALSE, otherwise TRUE. NOTES
Patterns and templates must often be enclosed in single quotes to turn off the special meanings of characters. Especially if you use the $m0 through $m9 variables in the template, since FMLI will expand the variables (usually to "") before regex even sees them. Single characters in character classes (inside []) must be listed before character ranges, otherwise they will not be recognized. For exam- ple, [a-zA-Z_/] will not find underscores (_) or slashes (/), but [_/a-zA-Z] will. The regular expressions accepted by regcmp differ slightly from other utilities (that is, sed, grep, awk, ed, and so forth). regex with the -e option forces subsequent commands to be ignored. In other words, if a backquoted statement appears as follows: `regex -e ...; command1; command2` command1 and command2 would never be executed. However, dividing the expression into two: `regex -e ...``command1; command2` would yield the desired result. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
awk(1), cut(1), grep(1), paste(1), sed(1), regcmp(3C), attributes(5) SunOS 5.11 12 Jul 1999 regex(1F)
All times are GMT -4. The time now is 08:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy