Sponsored Content
Full Discussion: Listing contents of fields
Top Forums Shell Programming and Scripting Listing contents of fields Post 303018479 by stumpyuk99 on Thursday 7th of June 2018 11:53:18 AM
Old 06-07-2018
Listing contents of fields

I am often given log files at work in .csv format to work with, normally extracting various fields. I then have to figure out the number of each field so that I can extract that field with cut or awk. Normally I just manually count the fields, based on the field separator. I would like to be able to take a line from the file and list the contents of each field along with the number of a field. Thus having the line of a file, such as:

Code:
apples,oranges,lemons,pears,peaches

I would like to see the output as:
Code:
1 apples
2 oranges
3 lemons
4 pears
5 peaches

I can then quickly see the columns that I need to extract.

I am aware of the "column" command, but often the files I have contain too many columns for this command to work.

Any help would be much appreciated
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies

2. UNIX for Dummies Questions & Answers

Listing the contents of a shared Unix library

I am brand new to Unix. This is probably simple, but how do you list the contents of a shared library? I need to see which functions exist in it. Many thanks. (1 Reply)
Discussion started by: mickpoil
1 Replies

3. UNIX for Dummies Questions & Answers

Listing out three fields of data

How would I find three different fields in a data file such as first name, last name, credit card number in a particular file? Thanks in advance for your help (3 Replies)
Discussion started by: damion
3 Replies

4. UNIX for Dummies Questions & Answers

Listing contents

Hello guys, I am having a requirement, I am having three file m1,m2,m3 having some contents. I want to list last 20 lines of m1,m2 and m3 all together on the terminal. I used tail -20 m1 m2 m3, but it is showing error, tail: option used in invalid context -- 2 Can u help me... (2 Replies)
Discussion started by: mraghunandanan
2 Replies

5. Solaris

Listing Contents of tar.gz file

Hi fellows, Can you please share any command with which I can list down the file names inside a tar.gz file. I have tried with these possibilities but in vain. bash-3.00$ tar -ztvf file.tar.gz tar: z: unknown function modifier bash-3.00$ tar ztvf file.tar.gz tar: z: unknown function... (1 Reply)
Discussion started by: Zaib
1 Replies

6. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

7. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

8. AIX

Slow listing of LTo5 tape contents

Hi, We are taking our filesystem backup having size of 1.3 TB on LTO5 catridges using the following command find * -print|backup -ivf '/dev/rmt0' '-U' i.e backup byname and it took about 6.5 Hours to complete When we are listing same tape contents using the following command restore... (1 Reply)
Discussion started by: m_raheelahmed
1 Replies

9. UNIX for Dummies Questions & Answers

Listing contents of .tar.gz files

Hi All, I would like to know couple of ways to list the content available in tar and gzipped file without extracting. i.e., I would like to display the contents of test.tar.gz without extracting. Note :: please suggest a command other that tar -ztvf (9 Replies)
Discussion started by: Girish19
9 Replies

10. Shell Programming and Scripting

Listing the contents of a file after a timestamp

Hi All I have a file which contains the timestamp of the log and a message and I want to implement a polling mechanism, where this log file is pooled every 2 minutes and list the errors in the file. I want to list down the errors only after the timestamp in the file is more than the current... (2 Replies)
Discussion started by: infyanurag
2 Replies
ARRAY_FLIP(3)								 1							     ARRAY_FLIP(3)

array_flip - Exchanges all keys with their associated values in an array

SYNOPSIS
array array_flip (array $array) DESCRIPTION
array_flip(3) returns an array in flip order, i.e. keys from $array become values and values from $array become keys. Note that the values of $array need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be included in the result. If a value has several occurrences, the latest key will be used as its value, and all others will be lost. PARAMETERS
o $array - An array of key/value pairs to be flipped. RETURN VALUES
Returns the flipped array on success and NULL on failure. EXAMPLES
Example #1 array_flip(3) example <?php $input = array("oranges", "apples", "pears"); $flipped = array_flip($input); print_r($flipped); ?> The above example will output: Array ( [oranges] => 0 [apples] => 1 [pears] => 2 ) Example #2 array_flip(3) example : collision <?php $input = array("a" => 1, "b" => 1, "c" => 2); $flipped = array_flip($input); print_r($flipped); ?> The above example will output: Array ( [1] => b [2] => c ) SEE ALSO
array_values(3), array_keys(3), array_reverse(3). PHP Documentation Group ARRAY_FLIP(3)
All times are GMT -4. The time now is 08:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy