Sponsored Content
Top Forums Shell Programming and Scripting How to add newline character at end of file? Post 302826895 by jnrohit2k on Thursday 27th of June 2013 02:16:49 PM
Old 06-27-2013
How to add newline character at end of file?

Code:
 
Hi All,
 
I have following piece of code in UNIX C Shell script and I want to add one more command which can add newline at the end of file only if there is no newline character exists.
 
   foreach file (`ls $dd_PLAYCARD_EDI_IN`)
    if ( -f $dd_PLAYCARD_EDI_IN/${file} ) then
      cat -n "$dd_PLAYCARD_EDI_IN/${file}"    | \
      perl -p -e "s/\x0d\x0a/\x0a/"  | \
      sed -e 's/00000000$/22991231/' | \
      sort -k1.18,1.29               >   $DATADIR/playcard/$file

Above "for loop" retrive the file from a directory then "cat" on each file to add line number, "perl" to remove ^M (control M) characters from the end of each line, "sed" will replace last 8 zeros with 22991231 and finally sort will sort the file. After "perl" command I want to add command which can add newline character at the end of file if it do not exists.
 
Please suggest.
 
Thanks!

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to add new line character at the end of a file

hi all, i have this question: How to add new line character at the end of a file???? i need this because i am loading a file to sybase and i have problems with the last record thanks for your help (5 Replies)
Discussion started by: DebianJ
5 Replies

2. Shell Programming and Scripting

Append newline at the file end

Hi All, Is there any way to append a newline character at the end of a file(coma-separated file), through shell script? I need to check whether newline character exists at the end of a file, if it does not then append it. Regards, Krishna (1 Reply)
Discussion started by: KrishnaSaran
1 Replies

3. Shell Programming and Scripting

How to remove a newline character at the end of filename

Hi All, I have named a file with current date,time and year as follows: month=`date | awk '{print $2}'` date=`date | awk '{print $3}'` year=`date | awk '{print $6}'` time=`date +%Hh_%Mm_%Ss'` filename="test_"$month"_"$date"_"$year"_"$time".txt" > $filename The file is created with a... (2 Replies)
Discussion started by: amio
2 Replies

4. Shell Programming and Scripting

add character to the end of each line in file

hi all i have 32 lines in file. the length of each line is 82 , i want that in the end of each line , means in postion 83-84 to put two characters 0d(=\015), 0a(=\012) i want that the 0d will be in postion 83 and the 0a will be in postion 84 in each line of the file how shall i do it ? ... (7 Replies)
Discussion started by: naamas03
7 Replies

5. Shell Programming and Scripting

add character to every end-of line in file

Hi All I have a file which conatins record.the length of every records is 47. problem : in the end of record i don't have a "\015" character. i want to add this "\015" charcter in the end of every record. the file contains something like 700 records. i've tried with sed command - nothing. ... (8 Replies)
Discussion started by: naamas03
8 Replies

6. UNIX for Dummies Questions & Answers

How to add newline before and after a special character?

So I have a file that contains >NM_#########AUGCAUCGUAGCUAGUCGAUACUGGACUG>NM_########AUGAGUAUGUAUGAUGUAUGUAUGA where # is any digit 0-9 (the text is many repetitions of the pattern above, not just that, but all in one line), and I want it to show >NM_#########... (2 Replies)
Discussion started by: ShiGua
2 Replies

7. Shell Programming and Scripting

Appending newline character End of File

Hi Gurus, Need help. I'm a beginner in Unix. I have a requirement, need to add or append newline (\n) character in file. Sample Data: 1|Main|Test|~# 2|Main|Hello|~# 3|Main|Unix|~# 4|Main|File|~#Output: 1|Main|Test|~# 2|Main|Hello|~# 3|Main|Unix|~# 4|Main|File|~#\n -- append only... (13 Replies)
Discussion started by: Gouri Solleti
13 Replies

8. Shell Programming and Scripting

Warning while sorting : A newline character was added to the end of file

Hi, I am trying to sort a csv file which has say 10 lines each line having a row size that is upto 30183 no. of COLUMNS (Row length = 30183). There is a LINE FEED (LF) at the end of each line. When I try to sort this file say, based on the second FIELD using the below command, sort -t ',' +1... (5 Replies)
Discussion started by: DHeisenberg
5 Replies

9. Shell Programming and Scripting

No newline at end of file

Hello all, I have maybe a simple Problem - but I do not know to handle it. All what I want, is to write a line to file without a newline at the end. It works with "echo -n" for all lines, but not for the last one. At the end of the file is always a "0a" (hex) My small script: ... (10 Replies)
Discussion started by: API
10 Replies

10. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies
Graph(3pm)						User Contributed Perl Documentation						Graph(3pm)

NAME
SVG::Graph - Visualize your data in Scalable Vector Graphics (SVG) format. SYNOPSIS
use SVG::Graph; use SVG::Graph::Data; use SVG::Graph::Data::Datum; #create a new SVG document to plot in... my $graph = SVG::Graph->new(width=>600,height=>600,margin=>30); #and create a frame to hold the data/glyphs my $frame = $graph->add_frame; #let's plot y = x^2 my @data = map {SVG::Graph::Data::Datum->new(x=>$_,y=>$_^2)} (1,2,3,4,5); my $data = SVG::Graph::Data->new(data => @data); #put the xy data into the frame $frame->add_data($data); #add some glyphs to apply to the data in the frame $frame->add_glyph('axis', #add an axis glyph 'x_absolute_ticks' => 1, #with ticks every one #unit on the x axis 'y_absolute_ticks' => 1, #and ticks every one #unit on the y axis 'stroke' => 'black', #draw the axis black 'stroke-width' => 2, #and 2px thick ); $frame->add_glyph('scatter', #add a scatterplot glyph 'stroke' => 'red', #the dots will be outlined #in red, 'fill' => 'red', #filled red, 'fill-opacity' => 0.5, #and 50% opaque ); #print the graphic print $graph->draw; DESCRIPTION
SVG::Graph is a suite of perl modules for plotting data. SVG::Graph currently supports plots of one-, two- and three-dimensional data, as well as N-ary rooted trees. Data may be represented as: Glyph Name Dimensionality supported 1d 2d 3d tree -------------------------------------------------------- Axis x Bar Graph x Bubble Plot x Heatmap Graph x Line Graph x Pie Graph x Scatter Plot x Spline Graph x Tree x SVG::Graph 0.02 is a pre-alpha release. Keep in mind that many of the glyphs are not very robust. PLOTTING
You need to create a SVG::Graph::Frame instance from the parent SVG::Graph instance for each set of data to be plotted. Datasets can be hierarchical, and to represent this, SVG::Graph::Frame instances can themselves contain subframes. SVG::Graph::Frame can contain: - multiple subframes as instances of SVG::Graph::Frame - a single SVG::Graph::Data instance - multiple SVG::Graph::Glyph instances with which to render the attached SVG::Graph::Data instance, and all SVG::Graph::Data instances attached to SVG::Graph::Frame subinstances See SVG::Graph::Frame and SVG::Graph::Glyph for details. ONE DATA SET 1. create an SVG::Graph instance 2. create an SVG::Graph::Frame instance by calling SVG::Graph::add_frame(); 3. create an SVG::Graph::Data instance, containing an SVG::Graph::Data::Datum instance for each data point. 4. Attach the SVG::Graph::Data instance to your SVG::Graph::Frame using SVG::Graph::Frame::add_data(); 5. Attach glyphs to the SVG::Graph::Frame instance using SVG::Graph::Frame::add_glyph(); 6. Call SVG::Graph::draw(); MULTIPLE DATA SETS 1. create an SVG::Graph instance 2. create an SVG::Graph::Frame instance by calling SVG::Graph::add_frame(); 3. create an SVG::Graph::Data instance, containing an SVG::Graph::Data::Datum instance for each data point. 4. Attach the SVG::Graph::Data instance to your SVG::Graph::Frame using SVG::Graph::Frame::add_data(); 5. Attach glyphs to the SVG::Graph::Frame instance using SVG::Graph::Frame::add_glyph(); 6. repeat [2-5] for each additional data set to be added. add_frame() can be called on SVG::Graph to add top-level data sets, or SVG::Graph::Frame to add hierarchical data sets. 7. Call SVG::Graph::draw(); FEEDBACK
Send an email to the svg-graph-developers list. For more info, visit the project page at http://www.sf.net/projects/svg-graph AUTHORS
Allen Day, <allenday@ucla.edu> Chris To, <crsto@ucla.edu> CONTRIBUTORS
James Chen, <chenj@seas.ucla.edu> Brian O'Connor, <boconnor@ucla.edu> SEE ALSO
SVG METHODS
new Title : new Usage : my $graph = SVG::Graph->new(width=>600, height=>600, margin=>20); Function: creates a new SVG::Graph object Returns : a SVG::Graph object Args : width => the width of the SVG height => the height of the SVG margin => margin for the root frame init Title : init Usage : Function: Example : Returns : Args : width Title : width Usage : $obj->width($newval) Function: Example : Returns : value of width (a scalar) Args : on set, new value (a scalar or undef, optional) height Title : height Usage : $obj->height($newval) Function: Example : Returns : value of height (a scalar) Args : on set, new value (a scalar or undef, optional) margin Title : margin Usage : $obj->margin($newval) Function: Example : Returns : value of margin (a scalar) Args : on set, new value (a scalar or undef, optional) svg Title : svg Usage : $obj->svg($newval) Function: Example : Returns : value of svg (a scalar) Args : on set, new value (a scalar or undef, optional) add_frame Title : add_frame Usage : my $frame = $graph->add_frame Function: adds a Frame to the current Graph Returns : a SVG::Graph::Frame object Args : a hash. usable keys: frame_transform (optional) 'top' default orientation 'bottom' rotates graph 180 deg (about the center) 'right' points top position towards right 'left' points top position towards left frames Title : frames Usage : get/set Function: Example : Returns : Args : xoffset Title : xoffset Usage : $obj->xoffset($newval) Function: Example : Returns : value of xoffset (a scalar) Args : on set, new value (a scalar or undef, optional) yoffset Title : yoffset Usage : $obj->yoffset($newval) Function: Example : Returns : value of yoffset (a scalar) Args : on set, new value (a scalar or undef, optional) draw Title : draw Usage : $graph=>draw Function: depends on child glyph implementations Returns : xmlifyied SVG object Args : none perl v5.10.0 2009-01-07 Graph(3pm)
All times are GMT -4. The time now is 04:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy