Asking on cut script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Asking on cut script
# 1  
Old 07-25-2003
Question Asking on cut script

Hi, as i spool some data into a tmp.log file ${SQL_LOG} which contained the below :

1 row updated.


1 row created.


111
----------
111


Commit complete.

then as i wanted to cut the value of 111 into a variable ,i put as this ksh script and echo it out:
JOB_ID=`head -10 ${SQL_LOG} | -b cut 1-10 '
echo $JOB_ID

but the echo will print as one straight line :
1 row updated. 1 row created. 111 ---------- 111

How do i write ksh script to cut the value 111 out ???

Thanks
# 2  
Old 07-25-2003
Got it, I had steal it from another forum, but I knew it was possible Smilie

I always struggle with grep'ing on linenumbers, but there is a very easy function from AWK :

JOB_ID=`awk 'NR>=8 && NR<=9 && /[[0-9]]*/ {print}' ${SQL_LOG}`

NR>=8 Means that linenumber must be above 8
/[[0-9]]* Means that it should match the characters 0123456789

I think it's quiet clear, if you don't make it to understand, please let me know.

Regs David
# 3  
Old 07-25-2003
Hi David,
thanks for your help !
Based on your script as shown below :

JOB_ID=`awk 'NR>=8 && NR<=9 && /[[0-9]]*/ {print}' ${SQL_LOG}`

As your /[[0-9]]* means it will get the line when it encounter any integer value ,right ??

so even if i wanted to cut a sentence in row 10 with 1111 on it , i could use the below script :

JOB_ID=`awk 'NR=10 && /[[0-9]]*/ {print}' ${SQL_LOG}`

Am i right??


thanks a lot!!

Last edited by blueberry80; 07-25-2003 at 11:03 AM..
# 4  
Old 07-25-2003
You're a quick learner Smilie

The question is answered in your original post.

Glad to be of service.


Regs David
# 5  
Old 07-26-2003
Hi,
thanks for your help but when i tried out using the script :

JOB_ID=`nawk 'NR=5 {print}' ${SQL_LOG}`

to cut from this log file :

1 row updated.
1 row created.
111
----------
111
Commit complete.


it will echo out this :
1 row updated. 1 row created. 111 ---------- 111 Commit complete.

instead of just getting out the '111'.

why is it that the log file become one straight line when i echo out and i am unable to cut the 111.

Thanks !
# 6  
Old 07-26-2003
cut -b 1-3
will do what you want.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies

2. Shell Programming and Scripting

Need script to cut string from a filename

Hi, I need a script which do below I have a filename: TEST2013_09_17_XX_XX_XX.csv Now script should create a new file with name: XX_XX_XX.csv Or I should say i need the output as XX_XX_XX.csv Please help. Mant thanks in advance (3 Replies)
Discussion started by: sv0081493
3 Replies

3. 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

4. Shell Programming and Scripting

Cut in shell script

Hi All, Am a Beginner to shell scripting, so please pardon my question. Below is the file format of file a.txt a.txt F=3 a|b|c|d 1|2|3|4 as|as|asd|asd Aas|as|asd|ada In the above file format, i have record count of total no of records excluding the header file here 3 , this varies... (2 Replies)
Discussion started by: sp999
2 Replies

5. UNIX for Dummies Questions & Answers

How to use cut or sed for my little script.

Hello people, I have a little script that has to compare some files (exe files)... so i find all the files in the given paths (2 paths) and it generates 2 txt files (named 1.txt and 2.txt, they have to be identical) i need to have a little IF function to compare the 2 files and see if they are... (2 Replies)
Discussion started by: valiadi
2 Replies

6. Shell Programming and Scripting

Cut out string in bash script

Hi all, I'm trying to extract string from variable in BASH. That's probably trivial for grep but I couldn't figure it out. I want to get name, there's sometimes digit after it, but it should be left out. STRING=http://name5.domain.com:8000/file.dat Could someone help me with that? Any... (10 Replies)
Discussion started by: cootue
10 Replies

7. UNIX for Dummies Questions & Answers

Cut an sql script output

Hi i want to cut the first field of this output obtained form sql script more dxlocks_test.log.1 SID SERIAL# SPID ---------- ---------- --------- 25 18356 1029 78 39370 1025 136 14361 1027 ================================ cut -f1... (2 Replies)
Discussion started by: aishwaryakala
2 Replies

8. Shell Programming and Scripting

Strange thing with 'cut' in a script

When I run the script I have just created, I get a strange scenario around the following code: echo "Check for duplicate UID's, each user should have a unique user ID (UID)" echo "IF a UID is displayed fix or document why it is required!" echo "Press enter to continue!" read a cut... (1 Reply)
Discussion started by: sport
1 Replies

9. Shell Programming and Scripting

script to cut a word from the file

hi to all i wrote a script to cut a word from the file....that works only if the word is fixed field. example.. sed -n '1p'|awk '{ print $2 }'|cut -d '(' -f2|sed 's/(//'|sed 's/)//'|sed 's/"//g' filename i know that word is starting with "app" then "(" ----> ex: app("xxxx"). it... (2 Replies)
Discussion started by: honeym210
2 Replies
Login or Register to Ask a Question