Search Results

Search: Posts Made By: kcpoole
2,940
Posted By Don Cragun
Oops. Actually, the middle segment above should...
Oops. Actually, the middle segment above should be:
REST="${REST%[[:space:]]}"
for event in $REST
do event="${event%[[:space:]]}"
[ ! "$event" ] && continue
2,940
Posted By Don Cragun
Sorry, I missed a closing brace: do [ !...
Sorry, I missed a closing brace:
do [ ! "${event%[[:space:]]}" ] && continue

I'll correct it in my earlier post.
2,940
Posted By Don Cragun
You can't get an exit code of -1 from a process...
You can't get an exit code of -1 from a process run by the shell.

Your comments about the format of center.txt described in your comments and the format of center.txt implied by the comments in...
2,100
Posted By RudiC
This may be what the requestor wants his bash...
This may be what the requestor wants his bash script to do:CNum=76
IFS="," read X cname csname < <(grep "^${CNum}," file); echo $CNum,$cname,$csname
76,Winston Hills,WIN


EDIT: Or, if you...
8,084
Posted By Scrutinizer
@alister, it would improve somewhat upon the...
@alister, it would improve somewhat upon the accepted solution, since expr is an external command, whereas printf is not, although both would be slower than your suggested variable expansion of...
8,084
Posted By alister
printf is a poor approach. Post #3 states that...
printf is a poor approach. Post #3 states that the result of stripping the leading zeroes will be saved for further use. To save printf's output, it's necessary to use command substitution, which...
8,084
Posted By MadeInGermany
Like the shell built-in numerics, printf "%d"...
Like the shell built-in numerics, printf "%d" treats a value with a leading 0 as an octal value, so 08 and 09 give error.
A workaround is printf "%.f".
8,084
Posted By MadeInGermany
while read v junk do wardevent=$((10#$v))...
while read v junk
do
wardevent=$((10#$v))
echo $wardevent
done < file
8,084
Posted By rbatte1
Dear pamu, How does your code react with the...
Dear pamu,
How does your code react with the following input? :-0001
0002 123
0003 HelloI regret that I get syntax errors for lines 2 & 3.



Robin
8,084
Posted By pamu
also while read line do ...
also


while read line
do
wardevent=$(expr $line + 0) # remove leading Zero from the line
echo $wardevent
done<file
1,939
Posted By RudiC
Did you peruse your shell's man page? This works...
Did you peruse your shell's man page? This works with recent shells:while read line
do #echo $line
gendage=${line:9:3} #Loc 9th character in the line and select the next 3 Char
...
2,057
Posted By MadeInGermany
@krishmaths: test wants = not == And the...
@krishmaths:
test wants = not ==
And the variable preset can happen once when placed just before the loop
yes="n"
until [ "$yes" = "y" ]
2,057
Posted By rdcwayx
#!/bin/bash # Put Values in an myarrayname and...
#!/bin/bash
# Put Values in an myarrayname and read them back
file="file.txt" # input filename

while read line ;do
wardevent=${line:3:2} # find the wardells...
2,057
Posted By krishmaths
You may need to loop it up until you get response...
You may need to loop it up until you get response as "y" like the following.


#!/bin/bash
# Put Values in an myarrayname and read them back
file="FILE.EXT" # input filename

yes="n"...
2,695
Posted By Don Cragun
The arithmetic expansion of $(($x)) when $x...
The arithmetic expansion of $(($x)) when $x expands to the string " 56" is 56.
Similarly, the parameter expansion of ${x##*[!1-9]} (which removes everything in the string before the 1st non-zero...
2,695
Posted By Don Cragun
So, with you new statement of what you want, try:...
So, with you new statement of what you want, try:
#!/bin/bash
#set initial variables
file="FILE.EXT" # input filename

IFS='"' read -r x cn x centnam x < "$file"
cn=${cn##*[!1-9]} # strip...
2,695
Posted By Jotne
awk -F "[^0-9]*" '{print $2,$3,$4}' 56 001 50...
awk -F "[^0-9]*" '{print $2,$3,$4}'
56
001 50 50
003 100 100
2,695
Posted By fpmurphy
#!/bin/bash file="FILE.EXT" while read...
#!/bin/bash

file="FILE.EXT"

while read line
do
centnum=${line:2:3}
centnam=$(echo $line | cut -d '"' -f4)
echo "D;$(($centnum));$centnam;;M;;"
done < $file

gives
...
Showing results 1 to 18 of 18

 
All times are GMT -4. The time now is 12:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy