Visit Our UNIX and Linux User Community

To check for a number inside the file in UNIX

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To check for a number inside the file in UNIX
# 1  
Old 09-03-2013
Scissors To check for a number inside the file in UNIX

Hi Gurus

I am a newbie to Unix programming and I am having a difficulty in finding out a number which is present in a file and storing it in a variable so that i can use it in my shell script.

The content of the file "count" is:

Count of the files=11

I need to just store the value 11 in a variable after reading the file so that i can use it in my script.The number can vary.It is not fixed

Is there any specific command to extract only the number from the whole string present in the file please?
# 2  
Old 09-03-2013
Is this a homework assignment?

Is there only one line in your input file?

Have you looked at your shell's built-in read utility?
# 3  
Old 09-03-2013
No this is not a homework assignment.I need the file count as an input to check in my 'if' loop.If the count of the file matches a specific number i need to perform some specific set of instructions.
There is only one line in the input file as mentioned above
I use a bourne shell
# 4  
Old 09-03-2013
Please share the command how you are counting file?
# 5  
Old 09-03-2013
3 examples:
cnt=`tr -dc '[0-9]' < count`
echo "$cnt"
cnt=`sed 's/[^0-9]//g' count`
echo "$cnt"
IFS="=" read junk cnt < count
echo "$cnt"
echo "$junk"

This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 09-03-2013
Originally Posted by MadeInGermany
3 examples:
IFS="=" read junk cnt < count
echo "$cnt"
echo "$junk"

I don't understand this part, It confuse me.
# 7  
Old 09-03-2013
Originally Posted by learnbash
I don't understand this part, It confuse me.
Field separator is set to =, so now as far as read is concerned, there are only 2 fields, Count of the files and 11. The first part will be read into the variable junk and the second part which is the number will be read into the variable cnt



Previous Thread | Next Thread
Test Your Knowledge in Computers #296
Difficulty: Easy
Linux Mint 2.0 was based on Ubuntu 6.10 and used the Ubuntu 6.10 package repositories and using it as a codebase.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if files inside a text file are found under a directory

Hi all, Please somebody help me with this: I want to check if the files listed in a text file, are found under a directory or not. For example: the file is list_of_files.txt, which contains inside this rows: # cat list_of_files logs errors paths debug # I want to check if these... (3 Replies)
Discussion started by: arrals_vl
3 Replies

2. Shell Programming and Scripting

How to check number of group of file.?

Hi Gurus, I need check existing number of file based on the list in file list. for example: in my file list. I have below: abc, file1.txt abc, file2.txt abc, file3.txt abc, file4.txt cde, filea1.txt cde, filea2.txt cde, filea3.txt ... in my current file direcotry, I have file:... (0 Replies)
Discussion started by: ken6503
0 Replies

3. Shell Programming and Scripting

find biggest number inside file

Hi, I wanna find the biggest number inside of a file this is kind of example of file: 9 11 55 then i just wanna print out the biggest number i had try sed filenale | sort -k1,1n | paste -s -d',' - but i had no success ... (7 Replies)
Discussion started by: prpkrk
7 Replies

4. Shell Programming and Scripting

Linux Shell Script to check for string inside a file?

This is what I have so far grep -lir "some text" * I need to check all files on the system for this text, if the text is found I need to change the file permissions so only ROOT has read and write access. How can this be done? (3 Replies)
Discussion started by: mapleleafs89
3 Replies

5. Shell Programming and Scripting

unzip a file then further check contents inside it

Dear all I need to unzip a file then further it has many folders to perform tak inside each folder. What Task I need to perform I'm able to do it but once I unzip a folder then I'm not able to do cd folder/ into it. I have written following code for it for i in $( ls | grep Run_20111016 ) do... (2 Replies)
Discussion started by: Bhalinder
2 Replies

6. Shell Programming and Scripting

How to insert a sequence number column inside a pipe delimited csv file using shell scripting?

Hi All, I need a shell script which could insert a sequence number column inside a dat file(pipe delimited). I have the dat file similar to the one as shown below.. |A|B|C||D|E |F|G|H||I|J |K|L|M||N|O |P|Q|R||S|T As shown above, the column 4 is currently blank and i need to insert sequence... (5 Replies)
Discussion started by: nithins007
5 Replies

7. Shell Programming and Scripting

KSH SHELL: problem calculation number of lines inside compressed file

Hi Gurus, I am working with a korn shell script to simplify some operations of calculation number of lines inside compressed file. The called function (inside a cycle) is the following: ######################################### # CheckCount #########################################... (3 Replies)
Discussion started by: GERMANICO
3 Replies

8. Shell Programming and Scripting

check number or character of a file

Hi, Please see the below information. 1. Read files one by one and run the script. 2. Check if the filename is CHARTER OR NUMBER 3. Run the case statement. I have files in the folder. i will get 300 files in a single day. Abc_111111111111.csv 101010_kkk_bbbb.csv... (6 Replies)
Discussion started by: onesuri
6 Replies

9. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

10. Shell Programming and Scripting

script to check for a condition inside a file

Hi I am writing a script file which sends the log files along with their size in a folder named log to a file called temp.log using the following cmd: ls -st 190_GSTV_HUX_003QISCGSK026** >> /home/user/temp.log the temp.log looks like this: 16 190_GSTV_HUX_003QISCGSK026_message070321.log ... (11 Replies)
Discussion started by: kiran1112
11 Replies

Featured Tech Videos