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 pass the line to the function. >>>The problem is when i try to cut the variable containing the $line0 I get an error cannot open...then it gives the proper value the first field in the line i'm trying to cut. It repeats this cannot open line for each column in the $line0 printing proper values.
I've seen other posts like this but none of the solutions have worked for me. Completely at a loss for new ideas desperate for help!
The syntax in this commented-out line is along the right lines but needed to preserve spaces in ${1}.
Quote:
#tfile= `echo "${1}" |cut -f2 -d ' '`
In this line (and many similar lines in the script) program "cut" is expecting ${line0} to contain a filename not a string ... hence "cannot open".
Quote:
lineValue2=`cut -f2 -d ' ' ${line0}`
I think that this will be an improvement:
Then apply the same syntax shift to other similar lines.
By the way, neither of the two functions in the script are actually executed but we can see that most of the code is in the while loop.
You will need to preserve spaces whenever there is more than one field. Though there is little point in copying ${line0}, this line needs quotes.
lineValue1="${line0}"
Methyl,
Thank you so much for helping. I'm still having problems but the additional quotes were very insiteful, wierd but insiteful. I was able to cut in teh loop but I was never able to send the line to the function. That is ok however because i was able to get each field from the string as if it was awk $1,$2,etc..
However, my call to the FindPath3 function is now broken and i have no idea why. It gets called but the ${1} is blank/ i've tried several different formats with the quotes with the parameter and echo statement but no luck. Any more ideas. I realize there are possibly other ways to accomplish my task, but my objective is to learn how to pass these parameters in the functions as well as achieve the end result. I'll need this ability for other code.
BTW, in order to get the cut to work i had to use the quotes and feed the cut with a pipe rather than pass it from the right side:
Methyl, thank you so much i never would have considered a space - !!!!!!! My code finally runs - thanks to you.
The object of the code was to find files over 1 gig write to a file then loop through the file, sending the file names to the find function, return the file location, Print it all out to a text file. It could be done differently w/less code but this syntax was really important to me. I still don't understand 2 things
1. In the final code sending the $Line0 to the my print, this was a string not a line. I could not use cut on this. Why is it a string not a line?
2. In the findPath3 function, I played around a lot with the syndax, why did i have to use the back ticks the way i did. I originally tried the line below but it returned nothing.
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)
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)
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)
I don't know if I described this right, but I am new to scripting and this is giving me a little bit of trouble, but I will explain what I am trying to do.
Each time this is run, I want it to grab and save ls -l /home to data.txt.
ls -l /home > data.txt
Now the part I am getting confused... (4 Replies)
The script is following :
for each_rec in <file_name>
do
count=`cut -c -2 ${each_rec} | grep "45"`
echo ${count}
if ] then
amount=`cut -c 24-35 ${each_rec}`
echo ${amount}
else
echo "failed"
fi
done
And the file looks like below :
... (4 Replies)
I am new to the c shell script, can you let me know why the set rr= is not working.
C shell script
#! /bin/csh
Set tt= 12345_UMR_BH452_3_2.txt
set rr='echo $tt | cut –d”_” -f1'
syntax error (4 Replies)
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)
I have a person running a perl script that is parsing > 2G log files and pipes to cut -d " " -f 1,6,7,8...
The script itself is in a nfs mounted home directory. It runs fine when started from a solaris 8 box but fails after about 400 lines when started from the solaris 10 box. The solaris... (1 Reply)