Find new line characters in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find new line characters in a file
# 1  
Old 08-15-2013
Find new line characters in a file

Hi All,

I need to find new line characters in a file and their location in the file and print the results. can someone pleas help.

KM
# 2  
Old 08-15-2013
try:
Code:
awk '{for (i=1; i<=length($0); i++) if (substr($0,i,1) ~ /\n/) print "Newline at character:",i}' RS= infile

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 08-16-2013
Quote:
Originally Posted by rdrtx1
try:
Code:
awk '{for (i=1; i<=length($0); i++) if (substr($0,i,1) ~ /\n/) print "Newline at character:",i}' RS= infile


Thank You.

How can i exclude the one which is at each end of the line.

Basically there are some end of the line characters in between the lines. So i just want to locate these end of the line characters which are in between the start and end of each line.

Thanks Again

---------- Post updated 08-16-13 at 11:04 AM ---------- Previous update was 08-15-13 at 06:15 PM ----------

Can someone please help.

I want to find and locate new line characters between start and end of each line from a file.

Thanks in Advance
# 4  
Old 08-16-2013
Quote:
Originally Posted by Kevin Tivoli
Thank You.

How can i exclude the one which is at each end of the line.

Basically there are some end of the line characters in between the lines. So i just want to locate these end of the line characters which are in between the start and end of each line.

Thanks Again

---------- Post updated 08-16-13 at 11:04 AM ---------- Previous update was 08-15-13 at 06:15 PM ----------

Can someone please help.

I want to find and locate new line characters between start and end of each line from a file.

Thanks in Advance
Your question makes no sense.

By definition, every line ends with a newline character. So, there can't be a newline character in the middle of a line.
# 5  
Old 08-16-2013
That's true for text files, and I think the requestor means text files, but you should also consider binary files.
Try
Code:
od -vw1 -tx1 -Ad file |grep 0a$
0000086 0a
0000181 0a
0000325 0a
0000484 0a
0000645 0a
. . .


Last edited by RudiC; 08-16-2013 at 07:38 PM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Find first 5 characters in the file name

Hi, I have some files in a folder. I need to find first 5 characters in the file name of every file and write those into a file. Example: ABC126_ACCPT.txt AYA127_ACCPT.txt Output in the file: ABC126 AYA127 (3 Replies)
Discussion started by: nani1984
3 Replies

2. Shell Programming and Scripting

Find out special characters from xml file

Hi....I have a xml file which is having lots of special characters which I need to find out and put the distinct list of those into a text file. The list of special characters is not specific, it can be anything at different point of time. Can anyone help me to find out the same and list out? ... (10 Replies)
Discussion started by: Krishanu Saha
10 Replies

3. Shell Programming and Scripting

Find word in file then get following characters

Hello, I have several xml files from which I want to find and return a particular string I want to locate the InId="00000008". Now that is inlcuded within a tag and ofcourse the number is different every time this is what I came up with given that after greping the line that contains the... (6 Replies)
Discussion started by: TasosARISFC
6 Replies

4. UNIX for Dummies Questions & Answers

find a word in a file, plus the next 6 characters?

I plan to use sed in a script to replace a string. My problem is the last 6 characters of the word to be replaced can be different each time, plus it's not always in the same spot on the line so I can't use cut or nawk to get the field. So I am looking for a way to find a certain word in a file,... (6 Replies)
Discussion started by: mikayla73
6 Replies

5. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 Replies

6. Shell Programming and Scripting

Delete new line characters from a file

Hi, I have a file with about 25 colums separated with '~', but few of the lines have extra tabs ('^') and new line characters ('$'). Is there a way I can delete those characters if they are anywhere before the 25th column in a line? example: CLUB000650;12345678;0087788667;NOOP MEMBER ... (4 Replies)
Discussion started by: rudoraj
4 Replies

7. UNIX for Dummies Questions & Answers

First Three Characters of the first line of a file

Dear Members, For example i have a file which contains 10 lines as below: 123testing gopjp jg9459\ 834789rh fh456 47rf 497rvg 409748\ 08ntr i need the first three characters of the first line of the file. if i use cut -c 1-3 < sample.txtits displaying the 1st three... (8 Replies)
Discussion started by: sandeep_1105
8 Replies

8. Shell Programming and Scripting

writing shell script to find line of invalid characters

Hi, I have to write s script to check an input file for invalid characters. In this script I have to find the exact line of the invalid character. If the input file contain 2 invalid character sat line 10 and 17, the script will show the value 10 and 17. Any help is appreciated. (3 Replies)
Discussion started by: beginner82
3 Replies

9. UNIX for Dummies Questions & Answers

Find and replace special characters in a file

HI All I need a shell script ehich removes all special characters from file and converts the file to UTF-* format Specail characters to be removed must be configurable. strIllegal = @"?/><,:;""'{|\\+=-)(*&^%$#@!~`"; Please help me in getting this script as my scripting skilla are... (2 Replies)
Discussion started by: sujithchandra
2 Replies

10. Shell Programming and Scripting

Find lines greater than 80 characters in a file

Hi, Can anyone please give me the grep command to find all the lines in a file that exceed 80 columns Thanks, gubbala (8 Replies)
Discussion started by: mrgubbala
8 Replies
Login or Register to Ask a Question