Sponsored Content
Top Forums Shell Programming and Scripting Print new item in file with symbol Post 302457150 by branred on Monday 27th of September 2010 10:48:48 AM
Old 09-27-2010
Print new item in file with symbol

Dear all,

I have encountered some problem here. I prompt the user for input and store it into a data file, eg. key in name and marks so the data file will look like this
andrew 80
ben 75

and the next input is carine 90. So the problem here is i want to print out carine with an asterik which will look like this.

*carine 90
andrew 80
ben 75

and the next new input is david 50 then it will look like this

carine 90
andrew 80
ben 75
*david 50
is there anyway i could achieve this?

I am doing this

Code:
print "\nPlease enter your name and marks :";

open (OUTFILE, ">>report");

$name = <STDIN>;
$mark = <STDIN>;
chomp ($name);
chomp ($mark);
print OUTFILE 
$abc = ("^$name\t$mark\n");
chomp ($abc);

close (OUTFILE);

and the printing out file is like this 

open (abc, "report") || die "Error opening data file: $!";

while (<abc>) { 
    push @array, [ split ];
foreach $list1 (@array) {
    foreach $list2 (@{$list1}) {
    print "'*'$list2\t";
}
print "\n";
}

Somehow this print out every element with *
Sorry for the messy code. And thank you in advance for any advice.

Last edited by vbe; 09-27-2010 at 12:04 PM.. Reason: code tags please
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get string from file after nth symbol

I've got a file, where I want to grab two fields from it. The file isn't fixed format, so all I know is that the two fields are after a certain number of delimiters within the record. File e.g. as follows:- "1"^"HEADER"^ "5"^"12345678"^"Smith"^"Dave"^"Mr"^"Research &... (1 Reply)
Discussion started by: daveaasmith
1 Replies

2. Shell Programming and Scripting

Remove the comment symbol ' from a file.

I want to remove the commented lines in a file identified by ' symbol at the start of each ine. A sample example will be like: Input ----- 'IFerr_flag=0THEN iferr_flag=0then iferr_flag=0then iferr_flag=0then iferr_flag=0then iferr_flag=0then iferr_flag=0then Output -------... (3 Replies)
Discussion started by: joyan321
3 Replies

3. Shell Programming and Scripting

Searching for file and stopping at first item found

Hello, I try to write a shell script that would list all files on a directory and stop when it finds the first item specified on a find or ls command. How can I tell to the find or ls command to stop when it finds the first ".doc" file for example ? Thank you (7 Replies)
Discussion started by: davchris
7 Replies

4. Solaris

/usr/lib/passwdutil.so.1: symbol __nsl_fgetspent_r: referenced symbol not found

deleteing post (0 Replies)
Discussion started by: dshakey
0 Replies

5. Shell Programming and Scripting

Reading each item from a formatted file

Hi, I have a file generated like this - 1. Fire SQL and store the formatted output in a temp file echo "select path, empid, age from emp_tbl" | /usr/sql emp_db 2 > count_file | grep vol > tempFile 2. The tempFile looks like this after the above statement /vol/emp1 0732 ... (9 Replies)
Discussion started by: angshuman_ag
9 Replies

6. Shell Programming and Scripting

awk to start with symbol and print next

File A >answer is the predicted other than >bigger than two >whatever isthere >out of mind CGAHHAWWASSASS SASAWEDSASSDDD SSDDDEDEUJUYYS >hello you are there other is what is that>you are not serious>leave it SSSAAAAAASS ASWWQQDDD WESEEWWWW WEEEEEWSS SJUJSGKKSSS SWBVHJJWUW >hi i... (3 Replies)
Discussion started by: cdfd123
3 Replies

7. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies

8. Shell Programming and Scripting

Read a lis, find items in a file from the list, change each item

Hello, I have some tab delimited text data, file: final_temp1 aname val NAME;r'(1,) 3.28584 r'(2,)<tab> NAME;r'(3,) 6.13003 NAME;r'(4,) 4.18037 r'(5,)<tab> You can see that the data is incomplete in some cases. There is a trailing tab after the first column for each incomplete row. I... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

9. UNIX for Beginners Questions & Answers

Zabbix item for last line of a log file

Dear all,Zabbix version : 2.4 (yes, I know, upgrading soon - honest) Server OS version : CentOS 6, 64-bit (CentOS 7 with the Zabbix upgrade)I've got a large log file that I would like to read by an external process. It's basically the same as reading the item value on a web-page. I have... (5 Replies)
Discussion started by: rbatte1
5 Replies

10. Shell Programming and Scripting

Script to process a list of items and uncomment lines with that item in a second file

Hello, I have a src code file where I need to uncomment many lines. The lines I need to uncomment look like, C CALL l_r(DESNAME,DESOUT, 'Gmax', ESH(10), NO_APP, JJ) The comment is the "C" in the first column. This needs to be deleted so that there are 6 spaces preceding "CALL".... (7 Replies)
Discussion started by: LMHmedchem
7 Replies
DMENU(1)						      General Commands Manual							  DMENU(1)

NAME
dmenu - dynamic menu SYNOPSIS
dmenu [-b] [-i] [-l lines] [-m monitor] [-p prompt] [-fn font] [-nb color] [-nf color] [-sb color] [-sf color] [-v] dmenu_run ... dmenu_path DESCRIPTION
dmenu is a dynamic menu for X, originally designed for dwm(1). It manages huge numbers of user-defined menu items efficiently. dmenu reads a list of newline-separated items from standard input and creates a menu. When the user selects an item or enters any text and presses Return, their choice is printed to standard output and dmenu terminates. dmenu_run is a dmenu script used by dwm which lists programs in the user's PATH and executes the selected item. dmenu_path is a program used by dmenu_run to find and cache a list of executables. OPTIONS
-b dmenu appears at the bottom of the screen. -i dmenu matches menu items case insensitively. -l lines dmenu lists items vertically, with the given number of lines. -m monitor dmenu appears on the given Xinerama screen. -p prompt defines the prompt to be displayed to the left of the input field. -fn font defines the font or font set used. -nb color defines the normal background color. #RGB, #RRGGBB, and color names are supported. -nf color defines the normal foreground color. -sb color defines the selected background color. -sf color defines the selected foreground color. -v prints version information to standard output, then exits. USAGE
dmenu is completely controlled by the keyboard. Besides standard Unix line editing and item selection (Up/Down/Left/Right, PageUp/Page- Down, Home/End), the following keys are recognized: Tab (Control-i) Copy the selected item to the input field. Return (Control-j) Confirm selection. Prints the selected item to standard output and exits, returning success. Shift-Return (Control-Shift-j) Confirm input. Prints the input text to standard output and exits, returning success. Escape (Control-c) Exit without selecting an item, returning failure. Control-y Paste the current X selection into the input field. SEE ALSO
dwm(1) dmenu-4.2.1 DMENU(1)
All times are GMT -4. The time now is 07:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy