[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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
?
478 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

656 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