Get the no. of lines in a text file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Get the no. of lines in a text file
# 1  
Old 05-20-2013
Get the no. of lines in a text file

Is there any work around to get no. lines in a text file and cut by total of 2 lines per file or whatever input parameter of command.

so for ei. this file
Code:
cat file1
1
2
3
4
5
6
7

Code:
filename output is incremental look like this:
linefile.txt  
1_linefile.txt
2_linefile.txt
3_linefile.txt

and if I cat linefile.txt should look like this:
1
2
and if I cat 3_linefile.txt should look like this:
7


Last edited by lxdorney; 05-21-2013 at 12:43 AM..
# 2  
Old 05-20-2013
Try:
Code:
wc -l

# 3  
Old 05-20-2013
sorry my post earlier is not complete

tahnks for the reply

---------- Post updated at 09:07 PM ---------- Previous update was at 06:33 AM ----------

anybody have an Idea to solve this?
# 4  
Old 05-20-2013
I see you want to split your input file into 2 lines per output file.

But your script doesn't make any sense. I don't see any step in your script which is trying to do this!

You can simply run a split command to achieve this:
Code:
split --lines=2 inputfile

# 5  
Old 05-21-2013
yes to split
thanks for the Idea
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

3. Shell Programming and Scripting

Read n lines from a text files getting n from within the text file

I dont even have a sample script cause I dont know where to start from. My data lookes like this > sat#16 #data: 15 site:UNZA baseline: 205.9151 0.008 -165.2465 35.8109 40.6685 21.9148 121.1446 26.4629 -18.4976 33.8722 0.017 -165.2243 48.2201 40.6908 ... (8 Replies)
Discussion started by: malandisa
8 Replies

4. Shell Programming and Scripting

How to delete lines of a text file based on another text file?

I have 2 TXT files with with 8 columns in them(tab separated). First file has 2000 entries whereas 2nd file has 300 entries. The first file has ALL the lines of second file. Now I need to remove those 300 lines (which are in both files) from first file so that first file's line count become... (2 Replies)
Discussion started by: prvnrk
2 Replies

5. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. UNIX for Dummies Questions & Answers

How to grep multiple lines from a text file using another text file?

I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

7. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

8. Shell Programming and Scripting

how to get the no. of lines in a text file

Hi, I want to count the no. of lines in a text file and print only the count(without file name) in another file with the prefix 'Count:'. I'm able to count the no. of lines present in the file using wc -l <filename> but i have to subtract one from the count and print as i dont need to... (8 Replies)
Discussion started by: vimalr
8 Replies

9. UNIX for Dummies Questions & Answers

get only some lines from a text file

Hi, I would like to know how can I get to a new file, some lines from an existing file. Like, I want to get the lines between 100 and 150. Best regards. (1 Reply)
Discussion started by: fadista
1 Replies

10. UNIX for Dummies Questions & Answers

Deleting lines in text file

Hi everyone, I have text files that I want to delete lines from. I have searched through this forum for quite some time and found examples of both awk and sed. Unfortunately, I was not able to successfully do what I want. Well to some extent. I did manage to delete the first 15 lines from each... (5 Replies)
Discussion started by: hern14
5 Replies
Login or Register to Ask a Question