Scripting - reduce output from grep to first 8 characters
Hi there
I have file.txt - a database with 2 fields. Each line contains 1) a reference number (4 digit integer) then a full-stop to seperate the 2 fields 2) A string name eg 0234. abcsefset 0567. bcfsdfse I am using a bash shell script to select each line in turn, and output the reference number: Code:
#!/bin/sh |
of course there is. echo $ref | cut -c -4
|
you can use awk command for this awkis a very powerful command.
awk -F '.' '{print $1}' file_name Hope this will help. |
Thanks - one more quick question - if I want to store this output (4 digit number) as a variable, what syntax would I use?
|
You already have it one variable, but to store in another is just as easy:
Code:
ID=${LINE%.*} |
Quote:
Code:
variable=$(echo $ref | cut -c -4) |
Quote:
@OP: Use grail's solution. |
All times are GMT -5. The time now is 04:04 AM. |