Sponsored Content
Top Forums Shell Programming and Scripting Insert text line to specific location CSV Post 302733031 by in2nix4life on Monday 19th of November 2012 02:58:59 PM
Old 11-19-2012
Code:
#!/usr/bin/perl
#

use strict;
use diagnostics;

my @data;
my @sorted_data;
my $csvfile = "details.csv";

open(FH, "<$csvfile") or die "Unable to open $csvfile.\n";
@data = <FH>;
@sorted_data = sort { (split ',', $a)[0] <=> (split ',', $b)[0] } @data;
foreach(@sorted_data) { print; }
close(FH);
exit(0);

This User Gave Thanks to in2nix4life For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert lines at specific location in file

Hi There I have this file that I would like to add entries to, however, there is a "}" as the last line that I need to keep. Basically i would like to know how I can write a script that will add new lines at the second to last line position (ie always add new line above the close bracket) ... (17 Replies)
Discussion started by: hcclnoodles
17 Replies

2. HP-UX

replacing text in specific location

i have a file that looks like this: 000000112/01/2008 D99999 000000 12/01/2008 D99999 000000 12/01/2008 1D99999 i need to replace the blanks into 1 for column 7,18-19 how can this be achieved using awk? Thanks. (1 Reply)
Discussion started by: zeontman
1 Replies

3. Shell Programming and Scripting

Insert 2 lines in a file at a specific location

Hi, I need to insert two new lines in a file: The file: "..... ...... ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`" .... .... " I need to add the lines: LD_LIBRARY_PATH='$LD_LIBRARY_PATH:$APACHE_HOME/modules' DOWNLOADMODULE_CONF_PATHNAME='$APACHE_HOME/conf/DWLModule.cfg' right... (2 Replies)
Discussion started by: potro
2 Replies

4. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

5. Shell Programming and Scripting

How to append a string to a specific location in a line

Hi, I have a to modify a line and insert a keyword in the middle to a specific location. My line looks like this FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS (ABC, DEF, GHI) I want to change it as FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' TRAILING... (4 Replies)
Discussion started by: mwrg
4 Replies

6. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

7. Shell Programming and Scripting

insert data into specific lines of a CSV

So I work in a 1 to 1 laptop deployment and sometimes we need to mass order parts. The vendor will send us a text file and we have to manually input serial numbers. Well I have a full blown web based inventory system which I can pull serial number reports from. I then have to input the part... (4 Replies)
Discussion started by: tlarkin
4 Replies

8. UNIX for Advanced & Expert Users

unix command : how to insert text at the cursor location via command line?

Hi, Well my title isn't very clear I think. So to understand my goal: I have a script "test1" #!/bin/bash xvkbd -text blabla with xbindkeys, I bind F5 key in order it runs my test1 script So when I press F5, test1 runs. I'm under Emacs/Vi and I press F5 in order to have "blabla" be... (0 Replies)
Discussion started by: xib.be
0 Replies

9. Shell Programming and Scripting

Interchange location of words in a line of csv file

Hi, I have a file with some info as example below. Its a csv file and i want to interchange the location of the times and dates in the 3rd and 4th fields only. I am using SunOS and csh script and would like to incorporate sed or nawk in the script (or any that would be able to accomplish this).... (5 Replies)
Discussion started by: viper1503
5 Replies

10. Shell Programming and Scripting

Insert character at specific location in a each line of the file

Hi All, I am trying to write a shell script where it should insert character 'I' in 180th position of each line(except first and last line) of the file. Below is the script for file in /home/test/bharat/*.RET do # Process file echo "File Name=" $file #l_fileName="${file##*/}" ... (19 Replies)
Discussion started by: bharath561989
19 Replies
PMLOAD(1p)						User Contributed Perl Documentation						PMLOAD(1p)

NAME
pmload - show what files a given module loads at compile time DESCRIPTION
Given an argument of a module name, show all the files that are loaded directly or indirectly when the module is used at compile-time. EXAMPLES
$ pmload IO::Handle /usr/local/devperl/lib/5.00554/Exporter.pm /usr/local/devperl/lib/5.00554/Carp.pm /usr/local/devperl/lib/5.00554/strict.pm /usr/local/devperl/lib/5.00554/vars.pm /usr/local/devperl/lib/5.00554/i686-linux/DynaLoader.pm /usr/local/devperl/lib/5.00554/i686-linux/IO/Handle.pm /usr/local/devperl/lib/5.00554/Symbol.pm /usr/local/devperl/lib/5.00554/i686-linux/IO/File.pm /usr/local/devperl/lib/5.00554/SelectSaver.pm /usr/local/devperl/lib/5.00554/i686-linux/Fcntl.pm /usr/local/devperl/lib/5.00554/AutoLoader.pm /usr/local/devperl/lib/5.00554/i686-linux/IO.pm /usr/local/devperl/lib/5.00554/i686-linux/IO/Seekable.pm $ cat `pmload IO::Socket` | wc -l 4015 $ oldperl -S pmload Tk /usr/lib/perl5/site_perl/Tk/Pretty.pm /usr/lib/perl5/Symbol.pm /usr/lib/perl5/site_perl/Tk/Frame.pm /usr/lib/perl5/site_perl/Tk/Toplevel.pm /usr/lib/perl5/strict.pm /usr/lib/perl5/Exporter.pm /usr/lib/perl5/vars.pm /usr/lib/perl5/site_perl/auto/Tk/Wm/autosplit.ix /usr/lib/perl5/site_perl/auto/Tk/Widget/autosplit.ix /usr/lib/perl5/site_perl/Tk.pm /usr/lib/perl5/i386-linux/5.00404/DynaLoader.pm /usr/lib/perl5/site_perl/auto/Tk/Frame/autosplit.ix /usr/lib/perl5/site_perl/auto/Tk/Toplevel/autosplit.ix /usr/lib/perl5/Carp.pm /usr/lib/perl5/site_perl/auto/Tk/autosplit.ix /usr/lib/perl5/site_perl/Tk/CmdLine.pm /usr/lib/perl5/site_perl/Tk/MainWindow.pm /usr/lib/perl5/site_perl/Tk/Submethods.pm /usr/lib/perl5/site_perl/Tk/Configure.pm /usr/lib/perl5/AutoLoader.pm /usr/lib/perl5/site_perl/Tk/Derived.pm /usr/lib/perl5/site_perl/Tk/Image.pm /usr/lib/perl5/site_perl/Tk/Wm.pm /usr/lib/perl5/site_perl/Tk/Widget.pm NOTE
If the programmers used a delayed "require", those files won't show up. Furthermore, this doesn't show all possible files that get opened, just those that those up in %INC. Most systems have a way to trace system calls. You can use this to find the real answer. First, get a baseline with no modules loaded. $ strace perl -e 1 2>&1 | perl -nle '/^open("(.*?)".* = [^-]/ && print $1' /etc/ld.so.cache /lib/libnsl.so.1 /lib/libdb.so.2 /lib/libdl.so.2 /lib/libm.so.6 /lib/libc.so.6 /lib/libcrypt.so.1 /dev/null $ strace perl -e 1 2>&1 | grep -c '^open.*= [^-]' 8 Now add module loads and see what you get: $ strace perl -MIO::Socket -e 1 2>&1 | grep -c '^open.*= [^-]' 24 $ strace perl -MTk -e 1 2>&1 | grep -c '^open.*= [^-]' 35 SEE ALSO
Devel::Loaded, plxload(1). AUTHORS and COPYRIGHTS Copyright (C) 1999 Tom Christiansen. Copyright (C) 2006-2008 Mark Leighton Fisher. This is free software; you can redistribute it and/or modify it under the terms of either: (a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or (b) the Perl "Artistic License". (This is the Perl 5 licensing scheme.) Please note this is a change from the original pmtools-1.00 (still available on CPAN), as pmtools-1.00 were licensed only under the Perl "Artistic License". perl v5.10.1 2010-02-22 PMLOAD(1p)
All times are GMT -4. The time now is 11:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy