?
Solved

Need a unix command set to list the file name and include the contents of the file on the same line with the file name within a unix shell environment

Posted on 2011-03-11
3
Medium Priority
?
477 Views
Last Modified: 2013-11-22
I have a directory with 100s of small text files that I need to extract the text contents.  

I need to get an output that will list the file name and contents of the file on the same line.

The contents of these text files is 80 ascii characters or less.  

example output format:

{file name} {contents of text file]
{file name} {contents of text file]
{file name} {contents of text file]
{file name} {contents of text file]
{file name} {contents of text file]


I am sure there is a simple unix shell command(s) that will allow this data to be extracted.

Here is a sample list of the files that I need to list and extract the data from:

-rw-rw-r--   1 easm     cog            8 Apr 12  2007 anc01520.dsc
-rw-rw-r--   1 easm     cog           15 Apr 12  2007 anc01521.dsc
-rw-rw-r--   1 easm     cog            4 Apr 12  2007 anc01522.dsc
-rw-rw-r--   1 easm     cog           27 Apr 12  2007 anc01523.dsc
-rw-rw-r--   1 easm     cog           17 Apr 12  2007 anc01524.dsc
-rw-rw-r--   1 easm     cog            9 Apr 12  2007 anc01525.dsc
-rw-rw-r--   1 easm     cog           16 Apr 12  2007 anc01526.dsc
-rw-rw-r--   1 easm     cog           16 Apr 12  2007 anc01527.dsc
-rw-rw-rw-   1 easm     cog           20 Dec  2  2008 anc03501.dsc
-rw-rw-r--   1 easm     cog           25 Apr 12  2007 anc04000.dsc
-rw-rw-r--   1 easm     cog           25 Apr 12  2007 anc04001.dsc
-rw-rw-r--   1 easm     cog           25 Apr 12  2007 anc04002.dsc
-rw-rw-r--   1 easm     cog           25 Apr 12  2007 anc04003.dsc
-rw-rw-r--   1 easm     cog           25 Apr 12  2007 anc04004.dsc
-rwxrwxr-x   1 easm     cog           30 Oct 31  2001 ancXXXXX.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21001.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21002.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21003.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21004.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21005.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21006.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21007.dsc
-rwxrwxr-x   1 easm     cog           15 Oct 31  2001 mc21008.dsc
-rwxrwxr-x   1 easm     cog           18 Oct 31  2001 mc21009.dsc
-rwxrwxr-x   1 easm     cog           18 Oct 31  2001 mc21010.dsc
-rw-rw-r--   1 easm     cog           23 Apr 12  2007 mc21012.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21018.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21019.dsc
-rwxrwxr-x   1 easm     cog           14 Oct 31  2001 mc21020.dsc
-rw-rw-r--   1 easm     cog           23 Apr 12  2007 mc21022.dsc
-rw-rw-r--   1 easm     cog           23 Apr 12  2007 mc21022.dsc.old
-rwxrwxr-x   1 easm     cog           18 Oct 31  2001 mc21023.dsc
0
Comment
Question by:longscuba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Expert Comment

by:aboo_s
ID: 35111984
You do have commands to list files in unix but I do not know of any command that will
list the file's content along with it's name!

I think you need to write down the code your self, with c/c++ perhaps!
0
 
LVL 7

Accepted Solution

by:
droyden earned 200 total points
ID: 35111989
if the files do not contain multiple lines then:

 
#!/bin/bash

ls *.dsc | while read i; do 
content=`cat $i`
echo -n "$i $content"
done

Open in new window

0
 

Author Closing Comment

by:longscuba
ID: 35133063
This script had to be modified to run under a ksh environment.

The script was accurate and works well for collecting the necessary data as requested.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
#Citrix #POC #XenDesktop #vCenter #VMware #ESX
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question