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
458 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
3 Comments
 
LVL 10

Expert Comment

by:aboo_s
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now