I would like to create a variable within my bash script using awk. I'm reading in a line from an external file, then outputting to a new file in a specific format. But, it doesnt quite work as I have expected and could use some help.
(A pertinent excerpt of ) the bash code is:
The file "stationlist" looks like
-94.998097,29.713967,WEST MAIN STREET,SH 146 NB
I want the output to be
sname="WEST MAIN STREET SH 146 NB"
but unfortunately it is
name="WEST MAIN STREET SH 146 NB
Curiously, if I instead replace line 5 above with
then I get
sname="WEST MAIN STREET"
which is almost what I want.
...
The file "stationlist" looks like
-94.998097,29.713967,WEST MAIN STREET,SH 146 NB
I want the output to be
sname="WEST MAIN STREET SH 146 NB"
but unfortunately it is
name="WEST MAIN STREET SH 146 NB
...
Ok, here's a hunch. If the name of the input file (1st input parameter) is actually "stationlist" and if that line (beginning with -94...) is the first line in there, then run this command:
Chances are, your output would look like this -
You will have to remove that "\r" from the file.
Do this -
If that doesn't work i.e. if "dos2unix" isn't present in your system, try "dos2ux". If that doesn't work either, then try the following 2 commands -
(I've assumed you don't already have a file called "my_temp_file" in your current directory.)
Thereafter, if the output of "od -bc" doesn't show the "\r" character, then your awk stuff should work -
Hi everyone,
I'm trying to write a small script to automatize row data treatment. However, I got some trouble with the awk command.
I want to use awk to extract a define paragraph from a text file. The first and final lines are defined externally in two variables called debut and fin.
I... (2 Replies)
Hi gurus,
I need to create arrays from variables, via a loop.
The issue I have is with the array name creation. How do I use a variable to define an array?
I want to do something like
declare -a $H
where $H is my loop variable.
I then need to add items to each array I've created,... (3 Replies)
I tried to parse data from switch configuration files
vlan 1727 name SQ5506-15 by port
tagged ethe 8/1 to 8/2
untagged ethe 1/13
!
vlan 2105 name SQ5620-7007(BR2) by port
tagged ethe 8/1 to 8/2
untagged ethe 1/17
!
interface ethernet 1/13
port-name SQ5506-15.nic0
rate-limit... (2 Replies)
Hi,
I'm trying to populate bash script variable, data_size with the
size of the largest file in my current directory
data_size=$(ls -lS | grep -v "total" | head -1) | awk '{ print $5 }'
I've tried adding an echo before the call to awk
data_size=$(ls -l | grep -v "total" | head -1) |... (2 Replies)
greetings all,
I am have a heck of a time trying to accomplish a very simple thing. I have an array of "shortname<spaces>id" created from a dscl output. I want to assign shortname=word1 and id=word2. I have tried
shortname=$(${textArray} | awk '{print $1}') - and get 'awk : cannot open... (3 Replies)
Hi,
Can someone help me with creating a bash shell script.
I need to create a script that gets a positive number n as an argument.
The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
hi all i am trying to save an awk value into an array in bash:
total=`awk '{sum+=$3} END {print sum}' "$count".txt"`
((count++))
the above statement is in a while loop..
$count is to keep track of file numbers (1.txt,2.txt,3.txt,etc.)
i get the following error:
./lines1:... (1 Reply)
I have a security system that FTPs the camera files to my machine, however I want to sort the pictures (taken every 30s) into directories by hour.
Every picture uses the following file format.
yymmddhhmmsstt.jpg (where tt is the milliseconds)
I am thinking the for loop is best
for file... (11 Replies)
I need some help making this script... I guess I'm having trouble even interpretating what to even get started on...
I need to create a script that will search a given directory (typically a user's home directory, but not necessarily) as provided on the command line and any sub-directors for... (2 Replies)