Sponsored Content
Top Forums Shell Programming and Scripting Cut command not working in for loop Post 302863715 by renuk on Tuesday 15th of October 2013 04:03:09 AM
Old 10-15-2013
Cut command not working in for loop

Code:
grep -Fxvf testdata.xls file_GTDA1.xls >file_GTDA.xls

SLS_COUNT=`grep 'GTDA_Dly_Sls' file_GTDA.xls |wc -l`
PMIX_COUNT=`grep 'GTDA_Dly_Pmix' file_GTDA.xls |wc -l`

if [ $SLS_COUNT -gt 0 ]; then
                var1=`cat file_GTDA.xls|grep 'GTDA_Dly_Sls_'`
                var4="|"
                for i in $var1
                do
                var3=`cut -d "$var4" -f18,19 $i|sort -u`
                var2=$var4""$var3
                sed -n 's/'"$var2"'//p' $i> ./temp/$i
#                sed -e 's/'"$var2"'//p' $i> ./temp/$i
                done
                echo " GTDA sales done"
fi

if [ $PMIX_COUNT -gt 0 ]; then
                var1=`cat file_GTDA.xls|grep 'GTDA_Dly_Pmix_'`
                var4="|"
                for i in $var1
                do
                var3=`cut -d "$var4" -f12,13 "$i"|sort -u`
                var2=$var4""$var3
                sed -n 's/'"$var2"'//p' $i> ./temp/$i
                done
                echo " GTDA Pmix done"
fi

when i am running above code it is giving me below error:
Code:
cut: GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv: No such file or directory
sed: can't read GTDA_Dly_Sls_SS_136_20130917.20130917205418.psv: No such file or directory
 GTDA sales done
cut: GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv: No such file or directory
sed: can't read GTDA_Dly_Pmix_AT_136_20130917.20130917205418.psv: No such file or directory
cut: GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv: No such file or directory
sed: can't read GTDA_Dly_Pmix_AT_136_20130917.20130917205619.psv: No such file or directory
cut: GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv: No such file or directory
sed: can't read GTDA_Dly_Pmix_AT_66_20130917.20130917205619.psv: No such file or directory
cut: GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv: No such file or directory
sed: can't read GTDA_Dly_Pmix_CA_12_20130917.20130917205619.psv: No such file or directory
 GTDA Pmix done

Thanks in advance!!!

Last edited by vbe; 10-15-2013 at 05:15 AM.. Reason: rm HTML...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use loop var i within Cut Command

Hi, In the following bash code rather than cutting at a predefined character I would like to cut at position i (i var from loop). Is this possible? I have tried eval, but either it's not possible or my syntax is wrong. thanks Nick for i in {1..9} do theChar=$(echo... (3 Replies)
Discussion started by: de_la_espada
3 Replies

2. UNIX for Dummies Questions & Answers

Cut not working in a loop

I have a function "MyPrint" that runs great on a file (BaseData.txt) that has one line of data. If i add rows to the text file it's reading the tFile variable becomes a list of every field 2 in the file. To correct this, i tried to call the function from a loop where i read one line at a time and... (4 Replies)
Discussion started by: KME
4 Replies

3. Shell Programming and Scripting

cut the present working directory

how to traverse through each directory (1 Reply)
Discussion started by: Reddy482
1 Replies

4. UNIX for Dummies Questions & Answers

cut not working the way i want it to

Hi Forum Im having problem with cut it even when i cut a field from an input file eg echo $x | cut -f1 -d':' it doesnt read the whole line if there is a space in it eg thisLineHasA SpaceInIt :wall: it only read up to the space.What i want is so the it cut the field as one line ... (8 Replies)
Discussion started by: ShinTec
8 Replies

5. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

6. UNIX for Dummies Questions & Answers

Cut command, no input delim, output delim not working

Hello, I'm using cygwin on my Windows 7 machine. From the man pages of cut: --output-delimiter=STRING use STRING as the output delimiter the default is to use the input delimiter I tried the following commands and got the error messages: $ cut -c1-10,20-30 -d... (10 Replies)
Discussion started by: kojac
10 Replies

7. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

8. Shell Programming and Scripting

CUT command not giving correct result inside loop

Hi, i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues. Src file(jjj.txt) -------... (8 Replies)
Discussion started by: raju2016
8 Replies

9. UNIX for Beginners Questions & Answers

Mv command in for loop - not working

HI Folks - I'm very frustrated - I'm trying to execute a verys imple for loop and rename the files if they exist. here is my loop : ydate=`TZ=aaa24 date +%m%d` CR_YR=$(date "+%Y") echo $ydate echo ${CR_YR} cd... (6 Replies)
Discussion started by: SIMMS7400
6 Replies

10. Shell Programming and Scripting

Why is my cut command not working ?

OS : RHEL 6.8 Shell : bash I want to remove all lines like below from the history output as it has password. $ history | grep sqlplus 239 sqlplus jn_usr/dxc825#@10.5.12.106/OCSGPD 256 sqlplus osb_soa/KD1egM09@10.5.12.196/BSOAPRD 279 sqlplus jn_usr/dxc825#@10.80.16.219/OCSGPD... (5 Replies)
Discussion started by: John K
5 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.10 12 Jul 1999 regex(1F)
All times are GMT -4. The time now is 06:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy