Print numbers along with file names.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print numbers along with file names.
# 1  
Old 10-30-2011
Print numbers along with file names.

Hi All,

I have some thousand files with names like 1.syl, 2.syl, 5.syl etc.

These files contain one sentence each. I want to store all those sentences along with the file ID that is 1, 2, 5 with the sentences they contain.

For example,

1.syl has

Code:
this is a test line

2.syl has

Code:
this is another line

5.syl has
Code:
I am done

I want my output to be like this:
Code:
this is a test line 1
this is another line 2
I am done 5

This is what I am trying on my Linux system but it is giving me error:


Code:
for num in `seq 1 1674` ; do
test ! -f $num.syl && continue
 "$i";echo;cat "$i"; done

# 2  
Old 10-30-2011
Code:
$ for i in *.syl; do line=$(cat $i); echo $line ${i%.*}; done
this is a test line 1
this is another line 2
I am done 5

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 10-30-2011
Code:
for i in *.syl;do echo $(<$i) ${i%.*};done

We don't need UUoC
This User Gave Thanks to danmero For This Post:
# 4  
Old 10-30-2011
Just in case...
UUoC = Useless Use of Cat

Code:
awk '{split(FILENAME,arr,".");print $0 FS arr[1]}' *.syl

--ahamed

Last edited by ahamed101; 10-30-2011 at 01:41 PM..
This User Gave Thanks to ahamed101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print the output with different file names

I have a python script that gives output called test.png. By using the following command I run the script every 2 seconds. What is the easiest way to save the output as follows ( test.png (1st output), tes1.png (second output), tes2.png ....) Command I i use while sleep 2; do python... (1 Reply)
Discussion started by: quincyjones
1 Replies

2. UNIX for Advanced & Expert Users

Find 2 occurrences of a word and print file names

I was thinking something like this but it always gets rid of the file location. grep -roh base. | wc -l find . -type f -exec grep -o base {} \; | wc -l Would this be a job for awk? Would I need to store the file locations in an array? (3 Replies)
Discussion started by: cokedude
3 Replies

3. Shell Programming and Scripting

Print file names in a loop

OS : RHEL 6.1 Shell : Bash I have lots of files in /tmp/stage directory as show below. Using a loop, I need to print all the filenames in this directory except those ending with a number. How can I do this ? # pwd /tmp/stage # # # ls -l * -rw-r--r--. 1 root root 0 Oct 7 18:38 stmt1... (2 Replies)
Discussion started by: kraljic
2 Replies

4. Shell Programming and Scripting

Using awk to append incremental numbers to the end of duplicate file names.

I'm currently working on a script that extracts files from a .zip, runs an sha1sum against them and then uses awk to pre-format them into zomething more readable thusly: Z 69 89e013b0d8aa2f9a79fcec4f2d71c6a469222c07 File1 Z 69 6c3aea28ce22b495e68e022a1578204a9de908ed File2 Z 69... (5 Replies)
Discussion started by: Ethereal
5 Replies

5. Shell Programming and Scripting

Shell Scripts (Renaming file names with sequential numbers)

Hi there, Firstly, I have no experience with shell scripts so would really appreciate some help. I have the following shell script that is causing some problems: moveit() { && set -x if then DOUBLE_DELIVERY=$(grep... (6 Replies)
Discussion started by: thebeno
6 Replies

6. Shell Programming and Scripting

Finding consecutive numbers in version names on a txt file

Hi all. I have a directory which contains files that can be versioned. All the files are named according to a pattern like this: TEXTSTRING1-001.EXTENSION TEXTSTRING2-001.EXTENSION TEXTSTRING3-001.EXTENSION ... TEXTSTRINGn-001.EXTENSION If a file is versioned, a file called ... (10 Replies)
Discussion started by: fox1212
10 Replies

7. UNIX for Advanced & Expert Users

How to select only those file names whose name contains only numbers

Hi Guru's, Before writing to this forum I have searched extensively on this forum about my problem. I have to write a shell script which takes out only those file names from the given directory which contains only numbers. For example, In the given directory these files are present: ... (4 Replies)
Discussion started by: spranm
4 Replies

8. UNIX for Dummies Questions & Answers

How to select only those file names whose name contains only numbers.

Hi Guru's, Before writing to this forum I have searched extensively on this forum about my problem. I have to write a shell script which takes out only those file names from the given directory which contains only numbers. For example, In the given directory these files are present: ... (0 Replies)
Discussion started by: spranm
0 Replies

9. Shell Programming and Scripting

how to remove files with only numbers as file names?

Hi all, I have a bunch of files that are named like 12543, 467249877, etc all over some directories.These files are named only with numbers, they dont have any letters or special characters in their file names. Could you please help me out and give me some command/script to remove only those... (6 Replies)
Discussion started by: praveen_indramo
6 Replies

10. UNIX for Dummies Questions & Answers

Need to print file names in a certain date range using ls

I need to list only file names of a specific date from the command ls -lt. :confused: (2 Replies)
Discussion started by: Shamwari
2 Replies
Login or Register to Ask a Question