Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-08-2016, 03:57 AM   #1
Upendra Pratap Singh
Registered: May 2011
Location: India
Distribution: Ubuntu 14.04
Posts: 110
Blog Entries: 4

Rep: Reputation: 0
Question map the name of the file with its content


I have some files which have only line

for example,

file1 has the content "A"
file2 has the content "B"
file3 has the content "C"

Now I have to create another file "result" that has the entry like

file1 A
file2 B
file3 C

How can I do this?
Old 01-08-2016, 04:09 AM   #2
Senior Member
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,489

Rep: Reputation: 921Reputation: 921Reputation: 921Reputation: 921Reputation: 921Reputation: 921Reputation: 921Reputation: 921
Something like this:
for f in <list of all your files>
    echo "$f $(<$f)"
done > result
The $(<....) operator is replaced by the file content.

I will leave the ironing out of wrinkles to you.
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sendmail permission issues? Getting dbm map "Alias0": unsafe map file /etc/mail/alias exxoid AIX 3 08-23-2014 06:47 AM
Dividing content of one file by content of another larspend Linux - Newbie 5 04-12-2011 08:00 PM
Shell script: substitute a file's content according to a map? Chowroc Programming 11 11-15-2005 04:08 AM
SYSERR(root): hash map "generics": missing map file /etc/mail/genericstable.db? singying304 Linux - Networking 4 02-28-2005 06:49 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:51 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration