English 中文(简体)
如何从档案中删除某一条线
原标题:How to remove a given line from a file
  • 时间:2011-05-12 23:50:04
  •  标签:
  • bash

我写了讲讲讲卫生运动的文字,把我们的公司内联网与我们的固定电子邮件服务器结合起来。 一种情况是,文字必须删除员额虚拟档案中的一条线,其形式如下(大部分是:电子邮件地址用户名称)。

    xyx@abc.com xyz
    tuv@abc.com tuv
    lmn@abc.com lmn

我的书本需要通过一个包含用户名(每行一个)的文档阅读,并从虚拟档案中删除相应的线。 因此,请说的是,它含有用户名称xyz的一条线;因此,在“可变编码”下的例子中,“usr正在储存<代码>xyz。

touch virtual.tmp
cat virtual | while read LINE ; do
if [ "$LINE" != "$usr@abc.com $usr" ] ; then
echo "$LINE" >> virtual.tmp
fi
done
rm -rf virtual
mv virtual.tmp virtual

然而,这部法律并不奏效,而且可能并不有效,因为我想要这样做的是删除一条基于用户名的线。 假设我不一定要阅读整个文件。

最佳回答

ry:

sed -i -e "/^$usr@abc.com/d" virtual

这应当从虚拟中删除线,无需写上字眼。

问题回答

你们有一份用户名称的档案和载有用户名称的记录(或流)。 a:

awk  
  FNR == NR {user[$1]++; next}
  !($2 in user) {print}
  users email_users > new_email_users 




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签